Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Return a value from show works for modal class forms
Message
 
To
17/02/2002 20:37:42
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00619243
Message ID:
00621433
Views:
13
Returning a value from a form is a quick fix and not particulary object object oriented. However it is nice for a quick fix, and i use it myself sometimes. If a form is to return values, Consider using this approach: Pass an object to the form during instantiation. Then allow the form to modify the properties of the object at will. It allows you to pass any number of values back from a form instantiated from a class or run from a DO FORM, and can even work with modeless forms as well. The form can even add new values to pass back that the calling code was not aware of (see cmdButton2).

This code can be entered in a prg, but the form class can be from a vcx as well. The only extra work this method requires is a couple lines to create the Passobj prior to form invocation.

Passobj = Createobject('shape')
Passobj.AddProperty('fname','')
Passobj.AddProperty('lname','')
Passobj.AddProperty('Address','')

Example code:
* cmdButton1 'cmdDoStuff1' passes back the values you requested
* cmdButton1 'cmdDoStuff2' passes back the values you requested, and some extra ones it want the calling object to know about.

********** code *************
Passobj = Createobject('shape')
Passobj.AddProperty('fname','')
Passobj.AddProperty('lname','')
Passobj.AddProperty('Address','')
frmObj = Createobject('cform',Passobj)
frmObj.Show()
Messagebox(Passobj.fname)
Messagebox(Passobj.lname)
Messagebox(Passobj.address)
If PEMSTATUS(Passobj,'phone',5)
Messagebox(Passobj.phone)
Endif

Define Class cform As Form
oPassObj = .Null.
WindowType = 1 && MODAL
Add Object 'cmdDoStuff1' As CommandButton ;
With Caption = 'DoStuff1', Height = 50

Add Object 'cmdDoStuff2' As CommandButton ;
With Caption = 'DoStuff and add extra property', ;
height = 50, Top = 100, Width = 300

Procedure cmdDoStuff1.Click()
Thisform.DoStuff1
Endproc

Procedure cmdDoStuff2.Click()
Thisform.DoStuff2
Endproc

Procedure Init(toObJ)
Thisform.oPassObj = toObJ
Endproc

Procedure DoStuff1
Thisform.oPassObj.fname = 'Fred'
Thisform.oPassObj.lname = 'Smith'
Thisform.oPassObj.address = '123 Main St.'
Endproc

Procedure DoStuff2
Thisform.oPassObj.fname = 'John'
Thisform.oPassObj.lname = 'Henry'
Thisform.oPassObj.address = '1902 Elm St.'
Thisform.oPassObj.AddProperty('phone','')
Thisform.oPassObj.phone = '999-909-1234'
Endproc

Procedure Destroy
Thisform.oPassObj = .Null.
Endproc
Enddefine


good luck
Cod...
Previous
Reply
Map
View

Click here to load this message in the networking platform