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

How to pass view parameters

Status
Not open for further replies.

k2a

Programmer
Jun 26, 2012
133
DE
Hi to all,
My form is bound to a view which requires some parameters passed to it. Right now i do this using public variables in the form's load method like this:

Public vp_recnr, vp_Status
vp_recnr = "%"
vp_Status = "open"

Using public variables for this purpose is not the best solution, also because i want to use that view in other forms too. Replacing public with private or local does not work.

Has anyone an ideas how to solve this?
Any suggestions are appreciated.

Regards, Klaus
 
just do this when you call the form.

do form myForm with '12345' && that is the value.

in the init of the form:
parameters tcValue && assuming it is character.

now, tcValue is the value you pased to it.

if you want to hold the value of the parameter throughtout the form, i would creaet a form propoerty.

and in the init, i would do this:
thisform.myParam = tcValue && now it is accessible throughout the form.



Ali Koumaiha
TeknoSoft Inc.
Michigan
 
In your case:

vp_recnr = "%"
vp_Status = "open"


do form YourFormName with "%","open"

in the init of the form:
Parameters tcrec,tcStatus




Ali Koumaiha
TeknoSoft Inc.
Michigan
 
Hi Ali,
Thank you for your help and quick response.

Super idea i definitely will use it! However, i'm still in the development stage. So how can i pass the parameters when click on Run Form?

Regards, Klaus
 
Klaus, you can't pass parameters when you click on Run Form. The solution Ali gave you is for when you run the form programmatically. If you want to run the form interactively in the development environment, you must run it from the Command Window. Just enter the code that Ali gave you, and hit Enter.

But note that will make the variables public, which is what you are trying to avoid.

Also, none of this has got anything to do with view parameters, which is the subject of your original question. Perhaps you could clarify whether you want view parameters or form parameters.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
In reagard of views the simple recommendation is to delay load of view data to form.init. So you set views NODATAONLOAD property true. In form.init(), where you can pass in form arameters, you then can also set view parameters with their value or use form parameters as view parameters and then REQUERY() the views that need those parameters, so in this way the requery really is the initial query of view data, just delayed to form.init.

You nevertheless already can bind views to form controls. This works even with the grid, which is very sensitive to undefined recordsources, the views already exist, only empty, until you requery. But you can make it one step cleaner, by setting forms.bindcontrols=.f. and just set this .t. at the end of form.init()

Bye, Olaf.
 
Hi Olaf,
Just coming back to your recommendation regarding parameter passing to views.
No matter what i do using NODATAONLOAD the view keeps asking me to enter the parameters.
Only declaring these parameters as public the view takes them without asking for it.

Did i misunderstood something?

Regards, Klaus
 
Where did you set NODATAONLOAD, and how is your view defined. Where and how does it use parameters? It depends if you can leave them undefined until a requery or need to define at least the names.

Bye, Olaf.


 
I place NODATAONLOAD to form.init and also to form.load. The view parameters are defined in the view's Filter section. Tried to define the names in form.init and also in form.data environment.code both as local but only public works.

Regards, Klaus
 
Form.Init and Form.Load are wrong. I'm not even sure what you're doing.

NoDataOnLoad is a property of cursor objects contained in the DataEnvironment. The property is set in the property sheet.

(You can USE theview NODATA, but that has nothing to do with the NoDataOnLoad property.)
 
Dan has already said what I would say.

So do you actually make use of the forms data environment at all? If not, that's also fine, then you have it in your hands where you open views. Form.Init is another nice place for it. Then you neihter need nodataonload property nor nodata option, as you then can set up parameters and open views.

You just need to learn about the form.bindcontrols property. As controls init before the form does, that should be .F. initially, otherwise especially grids will be problematic, if no empty views are already open and bound to them.

In form init you then open your views parameterised with values passed in to form.init() and then you finally set form.bindcontrols = .T. and controls bind to the data.

Bye, Olaf.
 
Sorry Dan,
cannot find the NoDataOnLoad property in the DataEnvironment. Can you please explain?
 
It's not in the dataenvironment itself. Its in the views, or as dan said it, it "is a property of cursor objects contained in the DataEnvironment".
You add view to the data environment and get a box showing field names. This is a cursor object. Right click on it and you find it's properties. If you don't have views there forget about it. Then the question is, where and how do you open views, by which code?

Bye, Olaf.
 
As Olaf explained, and as I previously said, NoDataOnLoad is not a property of the dataenvironment.

Now is as good a time as any to point out that you can navigate through objects in the property sheet from the object dropdown list that is above the list of properties. To get to the DataEnvironment and the cursor objects it contains, you have to open the DE first.

All of the cursor objects (whether view, table, or any other cursor object) will have a NoDataOnLoad property. The DE itself does not have a NoDataOnLoad property because the DE, itself, does not have any data. It is only a container for cursors and relations.
 
Finally i got it working, thanks to Olaf's detail explanation. This helps me to eliminate most of my public declarations.
Thank you Olaf, thank you Dan!

Regards, Klaus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top