Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to return a value from a form?
Message
 
To
27/11/2003 11:10:07
Mike Sue-Ping
Cambridge, Ontario, Canada
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00854035
Message ID:
00854053
Views:
18
Your code will not work and here is why.

When you issue the CREATEOBJECT() line, it only returns the object reference to the newly created form.
ofrmTest = CREATEOBJECT("frmparam", "string1", "string2") 
* The instance of the modal form is created, parameters are passed.

ofrmTest.Show() && or ofrmTest.Show(1) to make it modal
* Modal form is shown. 
* Code execution stops until the modal form is closed.
* If the form is closed, it is destroyed and ofrmTest=NULL then.

cChanged = ofrmTest.cReturnValue
* This line is pointing to non-existent object property, as the modal form is gone already

ofrmTest.Release()
* You are trying to call a method of non-existent form object.
* However 
RELEASE ofrmTest
*will release the variable that had a reference to the created form object.
To achieve what you want, you need to run your modal form with
DO FORM frmparam1 TO cChanged
where frmparam1 is a form (SCX) based on your frmparam form class (if you really need a form class here).

There are also other ways to get the property value that was changed in a form, for example through some parameter object that exists outside form and passed to the form by reference.

>Hi Nick,
>
>
>You can return a value from any modal form by putting a RETURN <value> in the unload event of the form.
>
>
>I do have a RETURN value in the form's unload event. The problem I'm having is, where or what is it returning to when I CREATEOBJECT()?
>
>Mike
>
>
>>See FAQ#7551 "How do I return a value from a form?"
>>
>>>I've created a form class that has a custom property to store a string. I'd like to pass this string back to the code that instantiated a from using the CREATEOBJECT() function. I've tried the following code but cannot get the return value.
>>>
>>>
>>>ofrmTest = CREATEOBJECT("frmparam", "string1", "string2")
>>>ofrmTest.Show()
>>>lcChanged = ofrmTest.cReturnValue
>>>ofrmTest.Release()
>>>
>>>
>>>It appears that the form object, ofrmTest, does not exist when I try to assign the variable, lcChanged.
>>>
>>>Any ideas where I may be messing up?
>>>
>>>TIA to all that reply.
>>>
>>>Regards,
>>>
>>>Mike
Nick Neklioudov
Universal Thread Consultant
3 times Microsoft MVP - Visual FoxPro

"I have not failed. I've just found 10,000 ways that don't work." - Thomas Edison
Previous
Reply
Map
View

Click here to load this message in the networking platform