Gene Griswold wrote:
> Eliot Friedman wrote:
> > I'm putting together an application where I need to initialize several
> > variables in Form1, then open Form2, do some stuff in Form2, then modify
> > the variables in Form1, and then return to Form1.
> > I'm having trouble accessing the Form1 variables from Form2. I'd rather
> > avoid the inelegant method of using a one-row table as a global value
> > repository, but all my attempts involving attaching to Form1 from Form2
> > seem to fail when I try to access anything inside Form1.
> > Anyone know what I'm doing wrong?
> > You can directly affect variables of another form. There are several
> ways to do it indirectly.
> You could have hidden field/text objects that can be attached by another
> form and their values changed.
> You could have library variables that can be called/set via lib methods
> used by both forms.
> You could have a method in the receiving form that is called by the
> sending form which controls the value of specific vars. I'll explain
> this way.
> Let's assume you have several vars you want to set remotely.
> First, define a form anytype dynamic array.
> Create a form method like setvar()
> method setvar(varname string,varval anytype)
> remvars[varname]=varval
> endmethod
> It's a good idea to initialize an element for each of your
> remotely-controlled vars early in the open process
> remvars["name"]=""
> remvars["bdate"]=""
> Enter a USES for the setvar() in the controlling form.
> After you open the controlled form, call setvar() each time you need to
> if cform.open("myform") then
> cform.setvar("name","George") and
> cform.setvar("bdate",date("01/01/96"))
> endif
> Gene G.
This is from borland T.I.
Using a library to pass a variable between two forms.
Version: All
Intended Audience:
Beginning to intermediate ObjectPAL users who are interested in
passing a variable between forms.
Prerequisites:
Familiarity with ObjectPAL libraries is helpful.
Purpose:
This document demonstrates how to use an ObjectPAL library to
pass a variable between two forms.
One way to pass a variable between two forms, is to use a
library. This document demonstrates how to make a library and
create custom methods within it. It also shows you how to create
two forms. One form uses a library's custom method to SET the
value of a variable, and the other uses the library's second
custom method to GET the value of a variable.
Create the Library:
1. Choose File | New | Library. Inspect the Library window
and select Methods. Select Var and press [Enter]. Your
code in this section should look like the following:
var
outgoing AnyType ; This variable will be returned
by
; the getVar() method
endVar
2. Check the syntax by pressing [F9].
3. Inspect the Library window and select Methods. Create a
custom method called setVar. To do this, double-click
<New Method>, type setVar, and press [Enter] (for version
1.0 and 4.5, type setVar in the New Custom Method text box
and press [Enter]). The code for the setVar custom method
should resemble the following:
method setVar(incoming AnyType) ; Passing an input
parameter
; Assigning the value of the
outgoing = incoming ; incoming variable to the
outgoing
; variable
endmethod
4. Check the syntax by pressing [F9].
5. Create a second custom method called getVar. The
following should resemble the code for the getVar custom
method:
method getVar() AnyType ; Returns an AnyType value
return outgoing ; Returns the value of the
outgoing
; variable
endmethod
6. Check the syntax by pressing [F9].
7. Click the Return button. Choose File | Save As and save
the library as VARLIB.LSL.
Create the First Form:
1. Choose File | New | Form, select a table name from the
Data Model dialog box and choose OK. From the Design
Layout dialog box, choose OK.
2. After the form appears on the screen in Design mode,
choose Properties | Form | Methods. Select Uses, Var, and
the open built-in method. Press [Enter]. Edit the code
in the Uses window to look like this:
uses ObjectPAL
setVar(inputVar AnyType)
endUses
Check the syntax by pressing [F9].
3. Edit the code in the Var window to look like this:
var
TheLibrary Library ; This is the Library
variable
inputVar AnyType ; This is the input variable
endVar
4. Check the syntax by pressing [F9].
5. Edit the code in the open method to look like this:
method open(var eventInfo Event)
if eventInfo.isPreFilter()
then
; This code executes for each object on the
; form.
else
; This code executes only for the form.
TheLibrary.open("VarLib")
; This will open the library in the
; GlobalToDesktop mode
endIf
endmethod
Check the syntax by pressing [F9].
6. Close each of the Editor windows.
Click the Button tool and create a pushbutton on your
form. Inspect it and press [Enter] or click on the button
name. The Object Name dialog box appears. In the Name of
Object text box, type SetButton, then choose OK. Select
the pushbutton label (i.e., the text field that says
"LABEL") and change it to SET.
7. Now, click the Field tool and create an undefined field on
your form. Inspect it and press [Enter] (or click the
field name). The Object Name dialog box appears. In the
Name of Object text box, type InputField, then choose OK.
8. Select the SetButton button and inspect it. From the
pop-up menu, select Methods. Select pushButton and press
[Enter]. The code in this pushButton method should
resemble the following:
method pushButton(var eventInfo Event)
inputVar = InputField.value
; Assigns the value of the
; InputField field to the
; inputVar variable
TheLibrary.setVar(inputVar)
; Sets the value of the
; library variable to the
; value of inputVar
endmethod
9. Check the syntax by pressing [F9].
10. Click the Return button. Choose File | Save As and save
this form as FORMONE.FSL. Double-click on the Control
Menu to close it.
Creating the Second Form:
1. Choose File | New | Form, select a table name from the
Data Model dialog box and choose OK. From the Design
Layout dialog box, choose OK. After the form appears on
the screen in Design mode, choose Properties | Form |
Methods. Select Uses, Var, and the open Built-in method.
Press [Enter]. Change the code in the Uses window to look
like the this:
uses ObjectPAL
getVar() AnyType
endUses
2. Check the syntax by pressing [F9].
3. Change the code in the Var window to look like this:
var
TheLibrary Library ; This is the Library
variable
outputVar AnyType ; This is the output
variable
endVar
4. Check the syntax by pressing [F9].
5. Edit the code in the open method window to look like this:
method open(var eventInfo Event)
if eventInfo.isPreFilter() then
; This code executes for each object on the
; form.
else
; This code executes only for the form.
TheLibrary.open("VarLib")
; This will open the library in the
; GlobalToDesktop mode
endIf
endmethod
6. Check the syntax by pressing [F9].
7. Close each of the Editor windows by clicking the Return
button. This button will save the source and exit the
editor.
8. Click the Button tool and create a pushbutton on your
form. Inspect it and press [Enter] (or click the button
name). The Object Name dialog box appears. In the Name
of Object text box, type GetButton, then choose OK.
Select the pushbutton label (i.e., the text field that
says "LABEL") and change it to GET.
9. Click the Field tool, and create an undefined field on
your form. Inspect it and press [Enter] (or click the
field name). In the Object Name dialog box, type
OutputField for the field name, and choose OK. Then,
click the GetButton button to select it, and inspect it.
Select Methods from the pop-up menu. Select the
pushButton method and press [Enter]. Your code in this
pushButton method should look like the following:
method pushButton(var eventInfo Event)
outputVar = TheLibrary.getVar()
; Assigns the value of the
; outgoing variable from
; TheLibrary to the
outputVar
; variable of the second
form
OutputField.value = outputVar
; Sets the value of the
; OutputField field to the
;
...
read more »