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

Access to Form properties and methods

Status
Not open for further replies.

EmmaLu

Programmer
Jul 16, 2004
38
US
Is it possible to access the properties and methods of a modeless child form from its modeless parent.

For example:

I create Form1 with a two command bottons: Button1 one code is "Do Form2" and Button1 two code is "Form2.Windowstate=1"

I run Form1 and press Button1 which opens Form2. Then when I press Button2 I receive the error "Object Form2 is not found".

This is just a simple example of what I am trying to do which is access properties and methods of one form from another. It seems to work from child to partent but not the other way. Is there a way around this?
 
Code:
*** Button1 Click:
IF NOT PEMSTATUS(thisform,[ChildForm],5)
   thisform.AddProperty([ChildForm],NULL)
ENDIF
DO FORM Form2 NAME thisform.ChildForm LINKED


**** Button2 Click
IF PEMSTATUS(thisform,[ChildForm],5) AND;
   NOT ISNULL(thisform.ChildForm)
   thisform.ChildForm.WIndowState = 1
ENDIF

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
Mike, sorry for the double post. I thought I posted that question but couldn't find it listed and I still can't see it or your answer. Would you mind directing me to it?
Thanks
 
EmmaLu,

It was quite a long answer. To be honest, I don't feel inclined to type the whole thing again. It's a pity that your original message has been deleted (not your fault).

Basically, I was suggesting you loop through _SCREEN.forms to get an object reference the form that you require.

Mike




__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
there are 2 ways To Do This: (without different buttons)

Code:
The simple way: If you will be using it In Only a few instances:

Scenerio: 2 Forms, Parent And Child

****Parent Form Init()
This.AddProperty("childform","")
****** To call child form 
Do Form childform With Thisform

**** Childform Init()
Lparameters pParentform
This.AddProperty("oParentForm",pParentform)
This.oParentform.childform = This

Now If you want To Minimize The Parent Form:
Thisform.oParentform.WindowState = 1
*** you can call any method, event, property or controls of the Parent form

If From Parent Form you want To Control The Child:
Thisform.childform.WindowState = 1

*************************************************
The Other way: If multiple Forms will be using This:
*************************************************

Create a Class (Custom) Add an Array With 2 Columns;
	Example: Class Name = FormMaster, Array Name = FormNames
From your Parent Form Create a Subclass
Public oFormMaster1
oFormMaster1 = Newobject("FormMaster")
oFormMaster1.FormNames[1,1] = Thisform.Name
oFormMaster1.FormNames[1,2] = Thisform

Now Call The Child Form(s)

****All ChildForm.INIT()
nLen = Alen(oFormMaster1.FormNames,1)+1
Dimension oFormMaster1.FormNames[nLen,2]
oFormMaster1.FormNames[nLen,1] = This.Name
oFormMaster1.FormNames[nLen,2] = Thisform

**** control child
oFormMaster1.FormNames[nLen,2].WindowState = 1
Or
**** control Parent
oFormMaster1.FormNames[1,2].WindowState = 1

ASCAN() can be used to find any form in the array


***** Parent Form Destroy()
Release oFormMaster1

If being Used By multiple Forms At once, Make sure your Subclass has different names
As it Is being declared Public And The Parent Form will Release The Class once done

Again: This Is To give you an idea On how it can be done; you will have To fine tune

 
Thanks Borislav and Mike. Both suggestions work great and my problem is solved. And thanks Mike for posting that again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top