Author |
Message |
Norman Hardwic #1 / 12
|
 Referencing the controls on a form from another form
Is there any way in VFP6.0 to reference controls on a form from another form without forcing both forms into a formset?
|
Sat, 17 Mar 2001 03:00:00 GMT |
|
 |
John Harve #2 / 12
|
 Referencing the controls on a form from another form
Yes, if the forms have names. If you do "do form x name form1" and then "do form y name form2", you can access the controls in form2 from a control in form1 by surfing the forms objects. From a command button on form1 issue form2.command1.click() if you have a control on form1 named command1. -- John Harvey http://home.att.net/~john.harvey/vfpstuff.htm Quote:
>Is there any way in VFP6.0 to reference controls on a form from another form >without forcing both forms into a formset?
|
Sat, 17 Mar 2001 03:00:00 GMT |
|
 |
Anders Altber #3 / 12
|
 Referencing the controls on a form from another form
_Screen.Forms(1) _Screen.Forms(2) up to _Screen.FormCount o1 = _screen.forms(1) o2 = _screen.forms(2) ? o1.grid1.column2.text1.value ? CompObj(Thisform, o1) _VFP.Objects is another collection you can explore, particularly if you're outside VFP. -Anders Quote:
>Is there any way in VFP6.0 to reference controls on a form from another form >without forcing both forms into a formset?
|
Sat, 17 Mar 2001 03:00:00 GMT |
|
 |
Norman Hardwic #4 / 12
|
 Referencing the controls on a form from another form
Quote:
>_Screen.Forms(1) >_Screen.Forms(2) up to _Screen.FormCount > o1 = _screen.forms(1)
Thanx for your reply. However, I had tried this already, but I get the error "'Forms' is not an object (Error 1924) (I do not have another occurrence of 'Forms' defined anywhere which is what's supposed to cause this error). Norm Quote: >_VFP.Objects is another collection you can explore, particularly if you're >outside VFP.
I have had no success with _VFP either, but perhaps I'm missing something. Norm
|
Sat, 17 Mar 2001 03:00:00 GMT |
|
 |
Norman Hardwic #5 / 12
|
 Referencing the controls on a form from another form
Quote:
>Yes, if the forms have names. If you do "do form x name form1" and then "do >form y name form2", you can access the controls in form2 from a control in >form1 by surfing the forms objects. From a command button on form1 issue >form2.command1.click() if you have a control on form1 named command1.
Thanx for replying. My case is not precisely what you have described. I have Do Form Form1. Then from within Form1, I have Do Form Form2. What happens is, Form2 can reference controls in Form1 with no problem, but if Form1 references a control in Form2, I get the error "Object 'Form2' is not found (Error1923)" Norm
|
Sat, 17 Mar 2001 03:00:00 GMT |
|
 |
Anders Altber #6 / 12
|
 Referencing the controls on a form from another form
Norman In VFP 5, look up Help _SCREEN and the Properties list. You'll find FORMCOUNT and FORMS(n). Open two forms from the Command window and run this code from the Command window activate screen public o1, o2 o1 = _screen.forms(1) o2 = _screen.forms(2) ? o1.controlcount ? o2.controlcount on key label f2 CompObj(_Screen.Activeform, o1) Activate the forms in turn and press F2. This works for me, so it would be interesting to find out why it doesn't for you. Give it another chance. -Anders Quote:
>>_Screen.Forms(1) >>_Screen.Forms(2) up to _Screen.FormCount >> o1 = _screen.forms(1) >Thanx for your reply. However, I had tried this already, but I get the >error "'Forms' is not an object (Error 1924) (I do not have another >occurrence of 'Forms' defined anywhere which is what's supposed to cause >this error). >Norm >>_VFP.Objects is another collection you can explore, particularly if you're >>outside VFP. >I have had no success with _VFP either, but perhaps I'm missing something. >Norm
|
Sat, 17 Mar 2001 03:00:00 GMT |
|
 |
Norman Hardwic #7 / 12
|
 Referencing the controls on a form from another form
Anders My apologies. Your code does indeed work. I had put in code in an attempt to identify which index applied to the form I was attempting to reference. I didn't realize that this code was unsuccessful and had caused the index to overflow. The invalid index value was what caused the error I got. Sorrrrry! Thanx - Norm Quote:
>Norman >In VFP 5, look up Help _SCREEN and the Properties list. You'll find >FORMCOUNT and FORMS(n). >Open two forms from the Command window and run this code from the Command >window >activate screen >public o1, o2 > o1 = _screen.forms(1) > o2 = _screen.forms(2) >? o1.controlcount >? o2.controlcount >on key label f2 CompObj(_Screen.Activeform, o1) > Activate the forms in turn and press F2. >This works for me, so it would be interesting to find out why it doesn't for >you. Give it another chance. >-Anders
|
Sat, 17 Mar 2001 03:00:00 GMT |
|
 |
Anders Altber #8 / 12
|
 Referencing the controls on a form from another form
CompObj(thisform, screen.forms(i)) should let you determine if the form is #1, 2 or 3 etc. -Anders Quote:
>Anders >My apologies. Your code does indeed work. I had put in code in an attempt >to identify which index applied to the form I was attempting to reference. >I didn't realize that this code was unsuccessful and had caused the index to >overflow. The invalid index value was what caused the error I got. >Sorrrrry! >Thanx - Norm
>>Norman >>In VFP 5, look up Help _SCREEN and the Properties list. You'll find >>FORMCOUNT and FORMS(n). >>Open two forms from the Command window and run this code from the Command >>window >>activate screen >>public o1, o2 >> o1 = _screen.forms(1) >> o2 = _screen.forms(2) >>? o1.controlcount >>? o2.controlcount >>on key label f2 CompObj(_Screen.Activeform, o1) >> Activate the forms in turn and press F2. >>This works for me, so it would be interesting to find out why it doesn't >for >>you. Give it another chance. >>-Anders
|
Sun, 18 Mar 2001 03:00:00 GMT |
|
 |
Loris Antonangel #9 / 12
|
 Referencing the controls on a form from another form
Quote:
> >_Screen.Forms(1) > >_Screen.Forms(2) up to _Screen.FormCount > > o1 = _screen.forms(1) > Thanx for your reply. However, I had tried this already, but I get the > error "'Forms' is not an object (Error 1924) (I do not have another > occurrence of 'Forms' defined anywhere which is what's supposed to cause > this error). > Norm > >_VFP.Objects is another collection you can explore, particularly if you're > >outside VFP. > I have had no success with _VFP either, but perhaps I'm missing something. > Norm
Are you sure you are issuing _SCREEN.FORMS(1) ???????? At least I get an error message when I issue _SCREEN.FORM(1) !!!!!!!!! forgetting the 'S' (Form <> FormS)... I must confess I am still using old VFP5... -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Loris Antonangeli, University of Oulu (Finland) phone: +358-8-5565456, +358-40-5015645
http://cc.oulu.fi/~loris/loris.htm Messages FOR FREE straight to my GSM-phone - follow instructions: 1) Go to http://www.mtn.co.za/sms/secure/text.html 2) Choose Network "Finland Telecom Finland 35840" 3) Enter my gsm-phone number +358405015645 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Ennen olin ep?varma - nyt en oikein tied?...
|
Sun, 18 Mar 2001 03:00:00 GMT |
|
 |
Joe Kaufm #10 / 12
|
 Referencing the controls on a form from another form
On Tue, 29 Sep 1998 13:02:42 -0400, "Norman Hardwick" Quote:
>>Yes, if the forms have names. If you do "do form x name form1" and then >"do >>form y name form2", you can access the controls in form2 from a control in >>form1 by surfing the forms objects. From a command button on form1 issue >>form2.command1.click() if you have a control on form1 named command1. >Thanx for replying. My case is not precisely what you have described. I >have Do Form Form1. Then from within Form1, I have Do Form Form2. What >happens is, Form2 can reference controls in Form1 with no problem, but if >Form1 references a control in Form2, I get the error "Object 'Form2' is not >found (Error1923)" >Norm
Right...you need to use the LINKED and NAME keywords when you instantiate the forms...for example, when you instantiate Form2 from Form1, do it thusly: PUBLIC frmForm2 DO FORM Form2 NAME frmForm2 LINKED and you will be able to access all of Form2's controls via frmForm2.<controlname>. I declare frmForm2 as PUBLIC because otherwise as soon as the variable frmForm2 goes out of scope, Form2 will disappear (that's what LINKED does...keeps the form instance and the reference to the instance in sync...) A better way than a PUBLIC variable would be to have a property of Form1 called "frmForm2", and then the above would just look like: DO FORM Form2 NAME THISFORM.frmForm2 LINKED Oh, wait, I am not sure if NAME will accept a property like that (well, according to the help I suppose it should...I usually use CREATEOBJECT() to create all my forms, so I would do something like: THISFORM.frmForm2 = CREATEOBJECT('Form2') Check out the help on DO FORM, and give note to the entries for NAME and LINKED...might get you where you need to be... Good luck! JoeK
|
Sun, 18 Mar 2001 03:00:00 GMT |
|
 |
Norman Hardwic #11 / 12
|
 Referencing the controls on a form from another form
Quote: >A better way than a PUBLIC variable would be to have a property of >Form1 called "frmForm2", and then the above would just look like: >DO FORM Form2 NAME THISFORM.frmForm2 LINKED >Oh, wait, I am not sure if NAME will accept a property like that
Joe Yes, it does. In fact, your solution in general works fine. Thanx very much for the help. Regards Norm
|
Mon, 19 Mar 2001 03:00:00 GMT |
|
 |
Norman Hardwic #12 / 12
|
 Referencing the controls on a form from another form
Quote:
>CompObj(thisform, screen.forms(i)) should let you determine if the form is >#1, 2 or 3 etc. >-Anders
Indies it does. Thanx again for your help. Norm
|
Mon, 19 Mar 2001 03:00:00 GMT |
|
|