Jump to content
Sign in to follow this  
Assembly

FUNCTION pass multi Values

Recommended Posts

I want a to be able to pass more than one value out of a function.

A handle and a Real.

GetBBox returns multiple values.

Can anyone show me how this works?.

Share this post


Link to post

This is probably an overly complicated example, but it runs:

Procedure Message_Double_Bounding_Box;

var	BBX1, BBY1, BBX2, BBY2 : Real;
	H1: Handle;
	S1: String;
	Bool1: Boolean;


Function Double_Bounding_Box(H2:Handle; var X1:real; var Y1:real; var X2:real; var Y2:Real) : Boolean;

Var XX1,YY1,XX2,YY2 :Real;

Begin
GetBBox(H2, XX1,YY1,XX2,YY2);
X1:=XX1-Distance(XX1,0,XX2,0)/2;
Y1:=YY1+Distance(0,YY1,0,YY2)/2;
X2:=XX2+Distance(XX1,0,XX2,0)/2;
Y2:=YY2-Distance(0,YY1,0,YY2)/2;
       Double_Bounding_Box:=False;
End;

Begin
S1:='  ';
BBX1:=0;
BBY1:=0;
BBX2:=0;
BBY2:=0;
H1:=FSActLayer;
Bool1:=Double_Bounding_Box(H1,BBX1,BBY1,BBX2,BBY2);
Message(Date(2,2),S1,BBX1,S1,BBY1,S1,BBX2,S1,BBY2,S1,Bool1);
End;

Run(Message_Double_Bounding_Box);

I think what you are asking about is the VAR's in the Function definition. If you include this and then change the value inside the function then the change is passes back to the calling function.

Note that where I set the BBX/Y's to zero is just to demonstrate that a change is made. It is not required in a real script.

The other way to return a value from a function is shown by defining the function to be of a certain type. Inside the Function just set the name of the function to the value you want to return.

If this is not clear enough, let me know and I will try again.

Share this post


Link to post

This is what I'm after in the most simple terms.

I want my function to return more than one Variable.

IE

FUNCTION DrawShapeGiveHandle(AndReturnWidth:REAL): HANDLE;

BEGIN;

Rect(0,0,1000,100):

DrawShapeGiveHandle:=lNewObj; {this gives me a handle to my shape}

AndReturnWidth:=1000; {this returns the width of shape}

END;

So I can do something like this

hTemp:=hDuplicate(DrawShapeGiveHandle(RealTemp),RealTemp,0);

This would allow me to duplicate the shape and return the width to space the duplicate all in one handy function.

Share this post


Link to post

To synthesize with Pat's comments, you need to prefix a returned variable with var, so your function definition would be:

FUNCTION DrawShapeGiveHandle(VAR AndReturnWidth:REAL): HANDLE;

In the body of your function, you would have:

AndReturnWidth:=someReal;

DrawShapeGiveHandle:=someHandle;

HTH,

Josh

Share this post


Link to post

Just declare it like this:

FUNCTION DrawShapeGiveHandle(VAR AndReturnWidth:Real):Handle;

The VAR in the declaration makes it use the actual variable (instead of the value) so that any changes inside the function are passed to the outside.

Share this post


Link to post
So I can do something like this

hTemp:=hDuplicate(DrawShapeGiveHandle(RealTemp),RealTemp,0);

You should probably test if the handle passed to hDuplicate is not NIL. Something like:

IF DrawShapeGiveHandle(objHdl,RealTemp) THEN

hTemp:=hDuplicate(objHdl,RealTemp,0);

Share this post


Link to post

Thanks everyone. New problem.

I want to use a function to pass an handle and real inside another function.

Something like this: (Miguel I do check for NIL but striped for quick reading)

Function Profile2DrawType1(ProfileRepeats:Real):Handle;

BEGIN;

Rect(0,0,300,10);

Profile2DrawType1:=LnewObject;

ProfileRepeats:=310;

END;

Function SelectProfile2ExtrudeAndRepeat(Profile:Handle):Handle;

BEGIN;

hTemp:=hExtrude(Profile,0,100);

hDuplicate(hTemp, ProfileRepeats,0);

END;

__________

Used like this:

HTemp:=SelectProfile2ExtrudeAndRepeat(Profile2DrawType1);

This works to draw the profile to extrude.

But I don't know how to to get the value returned for the ProfileRepeat value.

Can anyone help me... with this?.

Share this post


Link to post

Change the Function Definition to:

Function Profile2DrawType1(VAR ProfileRepeats:Real):Handle;

Whatever variable you put in during the function call (and you will have to put in a variable you can't use a constant), will have the value of profile repeats when the function exits.

Share this post


Link to post
Function Profile2DrawType1(VAR ProfileRepeats: Real):Handle;

BEGIN;

Rect(0,0,300,10);

Profile2DrawType1:=LnewObject;

ProfileRepeats:=310;

END;

Function SelectProfile2ExtrudeAndRepeat(Profile:Handle):Handle;

BEGIN;

hTemp:=hExtrude(Profile,0,100);

hDuplicate(hTemp, ProfileRepeats,0);

END;

__________

Used like this:

HTemp:=SelectProfile2ExtrudeAndRepeat(Profile2DrawType1);

Sorry, I was not clear, As you point out Pat I should have had the VAR.

Here is the problem...

When Profile2DrawType1 is called in SelectProfile2Extrude I can't figure out how to fetch the RepeatProfile value from inside the SelectProfile2Extrude function.

The SelectProfile2ExtrudeAndRepeat(requires a Handle to Draw). Profile2DrawType1 draws a shape and gives it a handle.

This works fine the extrude is created.

BUT, as I use the Profile2DrawType1 inside the variable settings of SelectProfile2ExtrudeAndRepeat-

HTemp:=SelectProfile2ExtrudeAndRepeat(Profile2DrawType1);

I don't see how to get the value through.

Share this post


Link to post

Change the function definition to:

FUNCTION SelectProfile2ExtrudeAndRepeat(Profile: HANDLE; ProfileRepeats: REAL): HANDLE;
VAR
 hTemp1,hTemp2: HANDLE;
BEGIN;
hTemp1:= hExtrude(Profile,0,100); 
hTemp2:= hDuplicate(hTemp1, ProfileRepeats,0);

SelectProfile2ExtrudeAndRepeat:= hTemp1;
{
or for the duplicate handle: 
SelectProfile2ExtrudeAndRepeat:= hTemp2;
}
END;

Share this post


Link to post

I think you will need to use a global variable to do what you want. The global variable could be set by by Profile2DrawType1 and then read by SelectProfile2ExtrudeandRepeat.

The variable to use could be passed in as a parameter to each function, but you need the external storage location to do the passing.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

 

7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114

 

© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

×
×
  • Create New...