Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Return a value from class form
Message
De
04/11/1999 11:43:43
 
 
À
04/11/1999 10:31:03
Steven Herbin
SNH Computing Corporation
Swan Lake, New York, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Classes - VCX
Divers
Thread ID:
00284777
Message ID:
00286931
Vues:
21
>>To add a little to Craig's answer, if you pass the calling form as an object
>>
>>obb = CREATEOBJECT("Myclassfrm",thisform,"Para2")
>>
>>the 'thisform' object can be used to update any property on the calling form.
>>
>>Make a property on the new form to hold the value.
>>
>>If the property is "oCallingForm", then
>>
>>thisform.oCallingForm.ValueINeed = thisform.ValueIWantToReturn
>>
>>HTH
>>Barbara
>>
>>>I have a form that needs to return a value to the calling program. I have made it into a class and wish to activate it with CREATEOBJECT().
>>>
>>>I know how to return a value from a form:
>>> DO form MyForm With Para1,Para2 to return_value
>>>
>>>But how can I do this if the form is saved as a class??
>>>
>>>obb = CREATEOBJECT("Myclassfrm","Para1","Para2") but how to return a value??
>
>Barbara-
>
>In your response (which I understand to a point), you said to make a property on the new form to hold the value -- would the property be "ValueIWantToReturn"?
>
>If so, that would make "ValueINeed" a property on the calling form.
>
>To refer to the property on the calling form from the "called" form, you would then need the indirection "thisform.oCallingForm.ValueINeed".
>
>But where and how does the "oCallingForm" property get created?
>
>This had me confused from day one of these kinds of discussions and I finally worked up the guts to say I don't get it!
>

It's pretty simple, actually. You'll need a property to save the reference to the calling form in your form class, and you'll need to pass the object reference to the calling form in the CREATEOBJ() for the form class instance.

In your form class, add a property called oParentForm. This is where the reference to the parent form will be stored in your form class.

In your form class's Init method, add an LPARAMETERS statement if you don't have one now, or if there is one now, add a parameter variable to the list. This is where the parent form object reference comes in.

When instantiating your form class instance, pass the parent form object reference as a parameter. For example, if you now create the object by saying:

oMyForm = CREATEOBJ('MyFormClass')

you'd now say

oMyForm = CREATEOBJ('MyFormClass',thisform)

this form in this case is the parent form. If your Init now begins with:

PROCEDURE INIT
LPARAMETER oParentRef

you'd add this bit of code to save the reference to the form property by:

thisform.oParentForm = oParentRef

In your code in the form class instance, you can reference properties in the parent form as:

thisform.oParentForm.name of property

so if you have a property nReturnValue in the parent form, you'd set it by saying something like:

thisform.oParentForm.nReturnValue = 42

You could also create a parameter object to pass values; there have been lots of threads on using parameter objects recently, as well as some writeups in the FAQ.
>--Steve.
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform