Subject Re: Simple parameter passing
From Mervyn Bick <invalid@invalid.invalid>
Date Wed, 28 Jan 2015 09:06:15 +0200
Newsgroups dbase.getting-started
Attachment(s) Unnamed File 1Unnamed File 2Unnamed File 3Unnamed File 4firstform.wfm
Unnamed File 6Unnamed File 7firstform1.wfmUnnamed File 9Unnamed File 10
firstform2.wfmUnnamed File 12Unnamed File 13Unnamed File 14





On Wed, 28 Jan 2015 03:23:38 +0200, Randy Waldman <randwald@comcast.net>  
wrote:

> Hi.  The mention of 'parameters' in Ken's book is overwhelming.  All I  
> want to do is "call a form (from an onclick of a form) and pass a  
> parameter to a sql on the 2nd form.
>
> Can someone shortcut the learning curve for me?

There are two ways of doing this.

The first way is to let the first form load the second form into memory  
and create an instance of it.  Now you can change properties of objects in  
the second form and when you are satisfied you can then useopen() (or  
readmodal()) to launch the second form.  Normally a form does not have a  
parent but if you set the first form as the second form's parent you can  
easily write values back to the correct parent form no matter how many  
copies of the first form are open.

The second way, which is preferred by OOP "purists" but takes more effort,  
is to DO the second form WITH parameters.  A standard form only has code  
to deal with a single logical parameter which is used to determine whether  
the form uses its open() or readmodal() method to launch it.  This means  
the second form has to have code in it to handle the additional  
parameter(s).  The easiest way to do this is to copy the "bootstrap" code  
from the form into the header section and then modify it.  It is important  
to add a "RETURN" after this modified bootstrap otherwise dBASE will  
simply execute the original bootstrap nullifying the whole exercise.

The second way is more in keeping with the idea of OOP programming but it  
does require more effort especially if you need to pass values back to the  
calling form.  findinstance() can find the parent form for you but a  
problem arises if more than one instance of the parent form can be open at  
the same time.  You then need code to enable the child to find the correct  
copy of the first form.  It's not particularly difficult but let's leave  
this until later.

Mervyn.