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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form parameter problem 1

Status
Not open for further replies.

aharrisreid

Programmer
Nov 17, 2000
312
GB

Using VFP 7, I have a pageframe with which I want the initially-activated page to be controlled according to the value of a parameter passed to the parent form. I would like to activate the page by checking the value of thisform.property from pageframe.init(), but the problem is at that stage form.init() has not yet fired, so the passed value has not yet been stored to a form property.

Q. Apart from activating the page at the end of form.init() (which will involve testing for the existance of the contained pageframe first), is there any other way of accessing a passed value before form.init() fires? Is there any other way of passing a value to a form such that it is available immediately?

Any help would be appreciated.

Alan
 
You could use a global (public) variable. This variable is set before calling your form, and is available everywhere in your form.
 
aprogrammer, thanks for the reply.

>>You could use a global (public) variable. This variable is set before calling your form, and is available everywhere in your form.<<

Unfortunately in this case the passed value must be unique to the form.

Regards,
Alan
 
aharrisreid

The sequence seems to be Load of the form, init of the pageframe and then init of the form, so pass the value to the load of the form.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
There is no way to pass the value to the Form's Load event...

The idea of activating the page at the end of the Form.Init event is the best idea. There really is no reason to put code in the PageFrame Init that is specific to the form... form related code should go in form methods/events.
 
wgcs

There is no way to pass the value to the Form's Load event...

I beg to differ on that. Use :
Var1 = &quot;12&quot;
do form myForm with var1


In the load of the form, calle the init() of the form with the var1 as a paramater.

Load of the form
thisform.init(var1)

Init of the form:
Lparamater lcVar1
messagebox(lcVar1)

And doing this changes the sequence of loading the form, and the init of that pageframe comes after the form's init().



Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Basically, this method is just defining a global variable (private in scope) before launching the form.

Think about it: How can the Load call:
Code:
thisform.init(lcVar1)
...if the Load doesn't have access to &quot;lcVar1&quot; already?

The only reason this example works is that the &quot;lcVar1&quot; variable is actually a Private variable, created before launching the form, and happens to have the same name as the parameter specified in the Init event, and so is in scope when the Load event fires.

Try:
Code:
RELEASE lcVar1
lcSomeOtherVariableName = &quot;whatever&quot;
DO FORM myForm WITH lcSomeOtherVariableName

or Try:
Code:
RELEASE lcVar1
LOCAL lcVar1
lcVar1 = &quot;whatever&quot;
DO FORM myForm WITH lcVar1

And the Load will blow up with Variable Not Found.

Init ends up executing twice, too: Once when called from Load, and once when the Init event actually fires.


aharrisreid:
It is generally bad practice to put code in the PageFrame that refers to conditions that may not exist: ie: if you put the pageframe on a form that doesn't get a parameter passed to it, then the code looking for that form parameter wouldn't apply. This is because doing this breaks &quot;encapsulation&quot;: the object should only do things that concern it.

The alternative of putting this code in the Form's Init is not a bad one: If you only put the code in the form that has the pageframe, then it isn't important to check for the pageframe's existance.
 
wgcs, thanks for the reply.

>>It is generally bad practice to put code in the PageFrame that refers to conditions that may not exist: ie: if you put the pageframe on a form that doesn't get a parameter passed to it, then the code looking for that form parameter wouldn't apply....If you only put the code in the form that has the pageframe, then it isn't important to check for the pageframe's existance.<<

I agree with you, except in this case I am looking for a generic solution to place in my own foundation class library. Either I have to test for presence of the parameter property in pageframe.init(), or test for the presence of the pageframe in form.init(). Either way I am breaking the encapsulation rule. Maybe I should be looking into a complete redesign of the class!

Regards,
Alan
 
I would would do one of two things.

Either just test for the presence of the pageframe in the forms init.

or

Create my form class without the page frame and related init code. The create a subclass of the form class with the pageframe and related init code. I this case you then just use the appropriate form class depending on whether you need a page frame or not.

In the second case you are not really breaking encapsulation because you can look a the form with pageframe as one class object. (Not that breaking encapsulation is really such a big deal.)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top