Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How To Know Parameter Passed By Reference?
Message
From
04/12/2005 22:16:01
 
 
To
29/11/2005 14:02:01
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows XP
Network:
Windows 2003 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01072940
Message ID:
01074815
Views:
16
Hi,

AFAIK this cannot be done with "normal" vfp variables.
If you REALLY want to, you could try to force a "contract" by forcing the parameters to be either arrays or objects. If an array isn't passed by reference, checks on the dimensionality should fail. Still, nothing beautiful IMHO.

Since passing an object passes an "object reference"/handle, it might be more appropriate. If the contract asks for an object, you could check the type(), isnull() and pemstat(toObject, "PropertyToStoreOutlookIn", 5)...

HTH

thomas

>Hey all,
>
>Kind of a theory question here... I want to know in a function whether or not a parameter has been passed by reference or value?
>
>I want to make a function that "returns" two things: an instance of Outlook.Application as well as a TRUE or FALSE indication of whether or not the instantiation was successful. Basically, something like:
>
>
>LOCAL loOutlook
>IF GetOutlookInstance(@loOutlook)
>    * Proceed using Outlook instance.
>ELSE
>    * Outlook object could not be instantiated.
>ENDIF
>
>
>The function GetOutlookInstance will try using GETOBJECT() within a TRY...CATCH where the CATCH forces the use of NEWOBJECT(). In other words, I want to attach to an existing instance of Outlook if I can, otherwise fire up a new one. Something like:
>
>
>FUNCTION GetOutlookInstance
>	* Attach to an instance of Outlook.
>	* RETURNS:  TRUE if attachment successful, FALSE otherwise.
>	LPARAMETERS poInstance
>	LOCAL loInstance
>	loInstance = NULL
>	TRY
>		* Try to attach to existing instance of Outlook
>		loInstance = GETOBJECT(, "Outlook.Application")
>	CATCH
>		* Attaching to Outlook failed, so create new instance.
>		loInstance = CREATEOBJECT("Outlook.Application")
>	ENDTRY
>	IF VARTYPE(loInstance) = "O"
>		* We have a valid instance.
>		poInstance = loInstance
>		RETURN .T.
>	ELSE
>		RETURN .F.
>	ENDIF
>ENDFUNC
>
>
>I want to make my GetOutlookInstance function bulletproof. I need to know whether the parameter being passed in is by reference or by value. It HAS to be by reference, otherwise assigning the instance of Outlook to it will have no effect in the calling code (and Outlook will close when the local loInstance variable goes out of scope).
>
>I know that I can check the variable type of loOutlook in the calling code, but I am trying to be elegant here. If I can make the function recognize the difference between value and reference, I can simply return FALSE when a programmer mistakenly calls the function without making sure the parameter is by reference.
>
>Any way of doing that?
>
>Thanks,
>JoeK
Previous
Reply
Map
View

Click here to load this message in the networking platform