Multiple instances of forms
This is an elegance question for an existing application.
CHALLENGE: We want to be able to open multiple instances of forms
to show multiple data items concurrently. In order to do this without
creating a new TForm descendant, we have chosen to have our security
module keep up with the multiple instances, as it already manages
form creation.
PROBLEM: Some popup forms, most of standard TForm class, need to
reference datasets on the parent form.
Is the best solution to:
Parent Module:
var fmParent: TfmParent;
...
fmChild.Create (Self);
Child Module:
var Parent: TfmParent;
...
OnCreate (Sender: TObject);
begin
Parent := TfmParent(Sender);
Parent.taTable.Open; {e.g}
end;
On a deeper level, when a form is created by the IDE, a variable
of type TForm is always created in the class (as opposed to the
implementation area) which is usually passed to the Application.Create
method. Is this a class or instance variable? (I know, RTFM).
In the sample code cited above, would the following work for
multiple instances?
Parent:
var
fmParent: TfmParent;
...
fmParent := Self;
fmChild.Create (fmParent);
Child Module:
uses ParentUnit;
...
OnCreate (Sender: TObject);
begin
fmParent.taTable.Open;
end;
Remember, ther will be multiple instances of this form. Which is the
safest, most reliable method.
TIA,
John Martin