For example, if a form in the background has a selected value in a
private data session field and I am in a different form and want to use
that value in the focused form, how do I reference that value?
Thanks in advance.
Beverly Howard
You can also send forms a parameter (DO FORM Whatever WITH lcValue), which
is received in the called form's INIT method. Store it in a property of the
called form.
If you have an object reference to the calling form, you can query
properties of that form object. I've been known to bring that about this
way:
Do Form Whatever With Thisform
Dan
At this point, assume that using public objects might be the best way to
do this on the assumption that they will be updated in the other forms
when they are repopulated in the source form.
On the
DO FORM Whatever WITH lcValue
...don't think will work with what I am attempting since both forms will
already be open so the user can switch back and forth to select/reslect
and fill the value into the other.
Back to the experimentation worktop ;-)
Beverly Howard
At what point to you want the order screen to change? Any time a new
customer is selected on the Customer screen? If so, then I would do
something like:
Have a PUBLIC object with properties for all of the items (like
customer number) that need to be communicated between forms. In that
object have methods to set each of the properties.
Whenever a form (like Customer) needs to change the 'current' customer
number, it calls the SetCustomer method in the public object. That
method stores the new customer number and then loops through all of
the forms (Screen.Forms), and any that have a specific method, say
ChangeCustomer, call that method to let the forms that care know that
the customer number has changed.
When a form opens that cares about the customer number, in its Load or
Init event it would get the current customer number from the public
object.
Another approach is to have the forms that care about each property
register with the public object. The public object would keep a list
of forms that want to be notified about each item.
>> At what point to you want the order screen to change? Any time a new
customer is selected on the Customer screen? If so, then I would do
something like: <<
Nothing will happen automatically... the user will need to take an
action in one form to retrieve the info from the other.... for example,
right click on the customer number field to insert the number from the
current customer record... going to run some experiments and be back.
Thanks for the inputs.
Beverly Howard
Am achieving what I need via a public object carrying a value from one
form to the next...
...but, that exposed the fact that the data sessions are not as I
expected... relationship in one form is impacting the data display in
the first form... the learning continues.
Beverly Howard
...breaktime
Beverly Howard
Dan
Beverly,
Add a method to the form - like OrderChange(CustNumber)
The other form can go through the screen's forms collection, find the form
there based on it having a method (see Pemstatus)
If the form is not there - it could launch it. If the form is already there
then it would just call the method - ie =FormObj.OrderChange(...)
Here's a function I use to find an instantiated form based on the caption -
which you can change
function Form_get_caption(_Caption)
_Caption = lower(m._Caption)
local obj
for each obj in _screen.Forms
do case
case type('m.obj.WindowType') == T_UNDEFINED
case at(m._Caption, lower(m.obj.Caption)) = 1
return m.obj
endcase
endfor
return null
endfunc
Here's one based on the Name of the form
#define TRUE .t.
#define FALSE .f.
eg find form Beverly
local obj
if( Form_get_name(@m.obj, 'Beverly') )
=m.obj.Customer_Change(123)
endif
function Form_get_name(obj, FormName)
local Success
Success = FALSE
FormName = lower(m.FormName)
for each obj in _screen.Forms
do case
case type('m.obj.WindowType') == T_UNDEFINED
case lower(m.obj.Name) == m.FormName
Success = TRUE
exit
endcase
endfor
do case
case m.Success
otherwise
obj = null
endcase
return m.Success
endfunc
Gregory
_
> >> At what point to you want the order screen to change? Any time a new
> customer is selected on the Customer screen? If so, then I would do
> something like: <<
>
> Nothing will happen automatically... the user will need to take an
> action in one form to retrieve the info from the other.... for example,
> right click on the customer number field to insert the number from the
> current customer record... going to run some experiments and be back.
If you ever have heard of design pattern: one solution for the communication
between forms would be the mediator pattern. In effect, it is close to what Jack
suggests.
Regards
Bernhard Sander
ahhhhhhhhhhh.... the headache is abating
Thanks all... still learning and progressing.
Beverly Howard
> >> good suggestions <<
> >> code samples <<
>
>ahhhhhhhhhhh.... the headache is abating
Not to worry. There will be others. <BEG>
>Thanks all... still learning and progressing.
I am still learning, too. One problem is sometimes it feels as
if the "still" means not moving.
Sincerely,
Gene Wirchenko
Computerese Irregular Verb Conjugation:
I have preferences.
You have biases.
He/She has prejudices.
Ouch! That hurt! ;-)
Beverly Howard
Thanks,
Beverly Howard
I would stay away from public variables if I could
Gregory
_
Wanting a forms manager is a good reason to start all apps from a framework.
HTH,
Eric
- Rush
To continue on the picky theme, PRIVATE isn't really a scope, so if
it's private, but in the top-level, it's essentially PUBLIC (though
you're right, it sticks around if you don't explicity release it or
quit VFP).