COntroling objects  
Author Message
General Fault





PostPosted: Visual FoxPro General, COntroling objects Top

I have 2 forms, Form1 and Form2.

In Form1 I have a grid and a button, when I click the button I call Form2.

What I want to do is to control the properties and methods of the grid inside Form1 from Form2.

How can I do this



Visual FoxPro2  
 
 
Aleniko





PostPosted: Visual FoxPro General, COntroling objects Top

One way is to pass to form2 a reference to the calling form. Like this:

do form2 with thisform

this way you can control anything you want in the calling form from form2 because now you have an object in form 2 which is the calling form.

Aleniko

 
 
General Fault





PostPosted: Visual FoxPro General, COntroling objects Top

So, if I wanted to change the RecordSource property in the grid inside Form1 from Form2 what should I do

Ok, first, call Form2 from Form1 with the following line

Do form2 with Thisform

And then what

Sorry for this kind of questions, I'm a beginner.


 
 
Alex Feldstein





PostPosted: Visual FoxPro General, COntroling objects Top

A form receives parameters in its INIT() method. Create a property of the form to keep the parameter received, therefore it will be in scope for the life of the form.

Form1.Button1.Click() (or in whatever method you want)

DO Form2 With this

In Form2.Init():

LPARAMETERS toForm

ThisForm.oForm = toForm

(no validation code included in example)

Now you have a reference in Form2.oForm to the object representing Form1.

Remember that VFP is Object Oriented, therefore you can manipulate the other form as an object.

HTH

See:

http://msdn.microsoft.com/library/default.asp url=/library/en-us/dv_foxhelp9/html/a727f12a-4d9f-45ca-aa01-c1bea7de9749.asp


 
 
General Fault





PostPosted: Visual FoxPro General, COntroling objects Top

So, having coded what you said before, if I wanted to change the RecordSource property in the grid inside Form1 from Form2 the only remaining thing for me to do is to write a line like the following

Thisform.oForm.Gridinform1.RecordSource="anothersource"


 
 
Aleniko





PostPosted: Visual FoxPro General, COntroling objects Top

Yes, but:

What I have learned here recently is that changing recordsource for a grid either at design time or at run time causes problems. I have had cases where my entire formatting/design/controlsource for the grid got lost because I changed the record source.


 
 
MarciaAkins





PostPosted: Visual FoxPro General, COntroling objects Top

So, if I wanted to change the RecordSource property in the grid inside Form1 from Form2 what should I do

Add a property called oCaller to form 2 and initialize it to .NULL. in the property sheet. You do this from the form menu ->New Property. This code goes in Form 2's Init():

LPARAMETERS toCaller

Thisform.oCaller = toCaller

Then the calling form is available from any method in form 2.

You manipulate the grid in form 1 by referring to Thisform.oCaller.<< Whatever the name of the grid in Form 1 is >>

If you are messing around with the grid's RecordSource, I suggest you read Andy's blog entry at http://weblogs.foxite.com/andykramek/archive/2005/03/19/174.aspx first to save yourself some aggravation.



 
 
General Fault





PostPosted: Visual FoxPro General, COntroling objects Top

Thanks to all of you.