Hi!
Do you know the WindowMenu property of a (parent) form?
It links to a menu that list all current MDI children of an application.
I want to list all existing children also in other place. More exactly I want to create an interface similar with Macromedia Dreamweaver or Delphi 7, where each MDI child has its own tab from where it can be quickly accessed.
I started the work from TForm.Notification but something is wrong.
The idea was to create a new tab in a TPageControl every time a form was created at runtime.
Somebody came with idea of adding a routine in each MDI form (in Create and Destroy) but I don't like the idea because I have many different forms derived from TFrom in my application.
The code that I tried is:
VAR
Initializing: Boolean= True;
FormID: Integer= 0;
procedure TfrmMain.Button1Click(Send
er: TObject);
VAR F: TForm;
begin
F:= TForm.Create(Self);
F.Caption:= 'xx';
F.Name:= 'Form'+ i2s(FormID);
F.Tag:= FormID;
F.FormStyle:= fsMDIChild;
F.Show;
F.BringToFront;
end;
procedure TfrmMain.FormCreate(Sender
: TObject);
begin
Initializing:= FALSE;
end;
procedure TfrmMain.Notification(ACom
ponent: TComponent; Operation: TOperation);
VAR btn: TButton;
begin
inherited;
if NOT Initializing
AND (Operation= opInsert)
AND (AComponent is TForm)
then
begin
inc(FormID);
btn:= TButton.Create(Self);
btn.Parent:= Self;
btn.Visible:= TRUE;
btn.BringToFront;
btn.Top := 1;
btn.Caption:= (AComponent as TForm).Caption; <--- AV here
btn.Tag:= FormID;
AComponent.Tag:= FormID;
end;
if (Operation= opRemove) then RemoveAsocButton;
end;
The code creates a MDI child when you push the button.
At this moment the Notification is aware that a new component is ready to be created. Here I want to create the list of existing MDI children (the above code tries to create a button for each of these MDI children). However it fails when at this line (AComponent as TForm).Caption.
The AComponent seems to be un-initialized.
PS: I also need the routine that deletes the corresponding button when its MDI child is closed.
PS: I accept also other approaches as long as they are elegant (for example if I dont need to insert code in all my derived forms). Maybe to create a MDI child and set a tab (TTabSheet) as its parent.
Start Free Trial