reference control on one form from another 
Author Message
 reference control on one form from another

Is it possible to reference a control on one form from another?

Thanks



Mon, 19 Dec 2005 02:57:42 GMT  
 reference control on one form from another
Hello, news.microsoft.com!
You wrote  on Wed, 2 Jul 2003 13:57:42 -0500:

 nmc> Is it possible to reference a control on one form from another?

Yes, there are few ways. Assume frmA has an editbox called edtMyEdit. In
form frmB, you want to access properties of frmA.edtMyEdit:

* sample 1:
DO formA NAME frmA && launch an instance of formA.scx and name it frmA
DO formB NAME frmB && launch an instance of formB.scx and name it frmB
*- in frmB:
frmA.edtMyEdit.value = "New value from within frmB"

* sample 2:
*- in frmA:
DO frmB WITH this.edtMyEdit
*- in frmB.init()
LPARAMETER toEditBox
toEditbox.value = "New value from within frmB"
*- save a reference to the toEditBox object in a custom property
*- so that you can access the object in different form methods
*- using thisform.o_editbox as reference.
this.addproperty("o_editbox", toEditBox)

Hope this makes sense.
--
Eric den Doop
www.foxite.com - The Home Of The Visual FoxPro Experts - Powered By VFP8



Mon, 19 Dec 2005 03:09:56 GMT  
 reference control on one form from another
Eric,
    I tried option 1 and I cannot get it to work.  Following is the code I
tried.

  Do FORM mailing NAME MLABEL && opens first form

On that form I have a button that opens another form
Do FORM LABEL

On the Label form the user clicks a command button and I want to set the
value of a text box (txtStartLabel).
MLABEL.txtStartLabel = 2

When this command executes, I get an error stating that object MLABEL does
not exist.

I am using VFP 7.0 by the way.

Thanks.


Quote:
> Hello, news.microsoft.com!
> You wrote  on Wed, 2 Jul 2003 13:57:42 -0500:

>  nmc> Is it possible to reference a control on one form from another?

> Yes, there are few ways. Assume frmA has an editbox called edtMyEdit. In
> form frmB, you want to access properties of frmA.edtMyEdit:

> * sample 1:
> DO formA NAME frmA && launch an instance of formA.scx and name it frmA
> DO formB NAME frmB && launch an instance of formB.scx and name it frmB
> *- in frmB:
> frmA.edtMyEdit.value = "New value from within frmB"

> * sample 2:
> *- in frmA:
> DO frmB WITH this.edtMyEdit
> *- in frmB.init()
> LPARAMETER toEditBox
> toEditbox.value = "New value from within frmB"
> *- save a reference to the toEditBox object in a custom property
> *- so that you can access the object in different form methods
> *- using thisform.o_editbox as reference.
> this.addproperty("o_editbox", toEditBox)

> Hope this makes sense.
> --
> Eric den Doop
> www.foxite.com - The Home Of The Visual FoxPro Experts - Powered By VFP8



Mon, 19 Dec 2005 03:43:37 GMT  
 reference control on one form from another
At the very least, try:
MLABEL.txtStartLabel.value = 2

Unlike VB, the value isn't the same as the textbox itself.

You should also probably declare MLABEL PUBLIC (or at least PRIVATE) - if it's scoped LOCAL the other form won't be able to "see" it.

Rick

Quote:

> Eric,
>     I tried option 1 and I cannot get it to work.  Following is the code I
> tried.

>   Do FORM mailing NAME MLABEL && opens first form

> On that form I have a button that opens another form
> Do FORM LABEL

> On the Label form the user clicks a command button and I want to set the
> value of a text box (txtStartLabel).
> MLABEL.txtStartLabel = 2

> When this command executes, I get an error stating that object MLABEL does
> not exist.

> I am using VFP 7.0 by the way.

> Thanks.


> > Hello, news.microsoft.com!
> > You wrote  on Wed, 2 Jul 2003 13:57:42 -0500:

> >  nmc> Is it possible to reference a control on one form from another?

> > Yes, there are few ways. Assume frmA has an editbox called edtMyEdit. In
> > form frmB, you want to access properties of frmA.edtMyEdit:

> > * sample 1:
> > DO formA NAME frmA && launch an instance of formA.scx and name it frmA
> > DO formB NAME frmB && launch an instance of formB.scx and name it frmB
> > *- in frmB:
> > frmA.edtMyEdit.value = "New value from within frmB"

> > * sample 2:
> > *- in frmA:
> > DO frmB WITH this.edtMyEdit
> > *- in frmB.init()
> > LPARAMETER toEditBox
> > toEditbox.value = "New value from within frmB"
> > *- save a reference to the toEditBox object in a custom property
> > *- so that you can access the object in different form methods
> > *- using thisform.o_editbox as reference.
> > this.addproperty("o_editbox", toEditBox)

> > Hope this makes sense.
> > --
> > Eric den Doop
> > www.foxite.com - The Home Of The Visual FoxPro Experts - Powered By VFP8



Mon, 19 Dec 2005 04:49:26 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Referencing the controls on a form from another form

2. Passing a reference from one form to another.

3. VFP 5.0: referencing one form from another

4. Referencing a form control from the main.prg

5. Referencing ALL of the controls in a form

6. referencing forms from other forms

7. referencing forms and their objects from other forms

8. Can't reference on forms properties from another form

9. Grid Control Expansive Reference

10. Help with ActiveX control property references

11. Referencing controls in a class

12. Making controls reference the correct class library

 

 
Powered by phpBB® Forum Software