Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MODELESS FORM

Status
Not open for further replies.

teknik

Programmer
Feb 27, 2001
33
IN
WE HAVE CALLED A MODELESS FORM FROM THE PRG
The code is :
PRIVATE m.n_item
m.n_item = 0
DO FORM XXX with A,B,C
IF m.n_item = 0
RETURN
ELSE
"FURTHER CODE"
ENDIF

The VARIABLE m.n_item is assigned a value in the forms Unload Method.The Form is modeless. but the Form executes only the init method hence the Value of variable remains 0 and "FURTHER CODE" is not executed.

Please give me some Solution.
Thanks In Advance


 
Hi,

PRIVATE m.n_item
m.n_item = 0
DO FORM XXX with A,B,C TO m.nitem
IF m.n_item = 0
RETURN
ELSE
"FURTHER CODE"
ENDIF

In the XXX Forms Unload event..
Create a form property..
myNitem

Based on where you pick up the value for this... put the code..
ThisForm.myNitem = whateverValue..
In the UNLOAD .... add the code..
RETURN ThisForm.myNitem

Noew you shall be thru :) ramani :)
(Subramanian.G),FoxAcc, ramani_g@yahoo.com
 
You'll also find you need to make the form model in order to return a value from it. Your problem in the first place is that with a modless form code execution continues in the program you used to call the form - so your variable doesn't get set in the unload event until sometime after you have checked it with 'IF m.nitem'

No way around this - the proper way is to make the form modal and then return the variable from the unload event with a 'DO FORM xxx WITH A,B,C TO m.returnvalue' type command.

:)
Ian
 
teknik

You variable goes out of scope when you load your form because it's private. Try what Ramani has suggested, or you can make it a Public variable. It will remain pass the form loading.
 
I don't believe that is correct. PRIVATE variables go out of scope after the procedure returns, but they are visible to any programs called by the procedure where they are declared (unless they also declare it PRIVATE or have a LOCAL variable by the same name). The PRIVATE command simply hides the specified variables or arrays that were defined in a calling program from the current program. It doesn't actually create any variables.

The code above will require a MODAL form to get the value back while in the same procedure.

Personally, I don't like programs or forms modifying PRIVATE or PUBLIC variables as a side-effect. It's hard to trace down those effects if there's a problem. I try to pass the values in and back if possible.

To get values back from a modeless form, I'd recommend passing in an object reference to the form with any values you want back as properties of the object. You can use a CUSTOM or SESSION class object, and call AddProperty() to add the properties if you don't want to define a class for the purpose.

Just store the passed in object reference as a property of the form in the form's Init method. That will keep a reference to it that you can use within the form that doesn't require PRIVATE or PUBLIC variables. Then in the form's Destroy() method, you can set whatever properties of the object that you want to pass back (and still reference any control properties if necessary).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top