Page 1 of 1

How To get all child forms ?

Posted: Fri Aug 07, 2009 1:16 pm
by ConvertFromOldNGs
by Didier >> Sat, 2 Feb 2008 5:16:12 GMT

Hi,
1) create a form named frmParent ;
2) create others forms named frmChild1, frmChild2,... and setFormParent whith frmParent ;

how to get all child forms of frmParent ?

Appreciate for any help .

Didier
2008.2.2

Re: How To get all child forms ?

Posted: Fri Aug 07, 2009 1:16 pm
by ConvertFromOldNGs
by Torrie Moore >> Sun, 3 Feb 2008 20:35:53 GMT

Unfortunately there is no inverse to the form parent. The only way to get the parent is to enumerate through the open forms and query their parent.

vars
i : Integer;
oParent : Form;begin

oParent := what ever parent form you're interested in;

foreach i in 1 to app.formsCount do
if app.forms(i).getFormParent = oParentForm then
// This form is a child form of oParent
endif;
endforeach;

If you need to access the form's parent and children, then you could setup an inverse between the forms. We have created a common superclass form which has this defined. All our forms are subclasses of this common form. For example on the child form add a myParent reference inversed to a collection allChildren on the parent form. (You may need to create a collection of forms, e.g. FormArray or FormSet etc. There is a FormNameDict (see Locale::getForms) but this may not work if you open the same form twice.) You can then reimplement the setFormParent method to also set your reference.

setFormParent(form: Form) updating;
// Sets the form parent.begin

inheritMethod(form); // Let Jade do its stuff
myParentForm := form; // Also set the local reference
end;

Cheers

Torrie

Re: How To get all child forms ?

Posted: Fri Aug 07, 2009 1:16 pm
by ConvertFromOldNGs
by cnwtb2 >> Sun, 3 Feb 2008 22:57:36 GMT

....or you could get the class names of the child forms by using the Class::allLocalSubclasses method (and other such methods) and manipulate the Class(s) returned. i.e.

(note: FrmParent is the Class not the Object of a Class)

vars
oClassColl : ClassColl;
oChildClass: Class;
begin
create oClassColl transient;
FrmParent.allLocalSubclasses(oClassColl);

foreach oChildClass in oClassColl do
write oChildClass.name; // manipulate the findings
endforeach;
epilog
delete oClassColl;
end;