1

got here a two Forms which are both set to fsMDIForm . And two Child Forms fsMDIChild.

When I run the Application it looks like both Parent Forms are correctly created because I can see the Space where the Child Forms would show up.

But for some reason the the Second MDIForm which is created from the Main MDI Form the Children are not being displayed, instead they are created on the Main MDI Form .

This is how the Second MDI Form is created

procedure TMain.menChefReportClick(Sender: TObject);
begin
  Timer1.Enabled:=false;
  CloseAllMDIChildren;

  Application.CreateForm(TChefReport, ChefReport);
  ChefReport.PopupParent:=Main;
  ChefReport.ShowModal;
  ChefReport.Free;
  ChefReport:=nil;

  OpenAllMDIChildren;
  Timer1.Enabled:=true;
end;

This closes all MDI Children for the Main Form , I am doing this because I am displaying Live data which is not required as long as I am in the Second MDI Form.

On the Second MDI form I am trying to create the Children like this :

procedure TChefReport.OpenAllMDIChildren;
var AQuery : TADOQuery;
    Y : integer;
begin
  AQuery := TADOQuery.Create(nil);
  try
    AQuery.Connection:=dmConnection.XLR;
    AQuery.LockType:=ltReadOnly;
    AQuery.SQL.Clear;
    AQuery.SQL.Add('select Line from LINE_SETTINGS order by line');
    AQuery.Open;

    AQuery.DisableControls;

    Y:=0;

    while not AQuery.Eof do
    begin
      Application.CreateForm(TChefReportLine,ChefReportLine);

      ChefReportLine.Caption:='Linie Nr. '+AQuery.FieldByName('Line').AsString;
      ChefReportLine.FLine:=AQuery.FieldByName('Line').AsInteger;

      ChefReportLine.Top:=0;
      ChefReportLine.Left:=0;

      Y:=Y+ChefReportLine.Height;


      AQuery.Next;
    end;

  finally
    AQuery.Free;
  end;
end;

It does create them . But unfortunately on the Main MDI Form .

Is it possible and how do I create them on the Second MDI Form ( ChefReport ) ?

Thank you!

UPDATE

Solutions was here : Allow multiple MDI Parent Forms on same Application

And I create the Children Like this :

procedure TChefReport.OpenAllMDIChildren;
var AQuery : TADOQuery;
    Y : integer;

    ChefReportLine : TChefReportLine;
begin
  AQuery := TADOQuery.Create(nil);
  try
    AQuery.Connection:=dmConnection.XLR;
    AQuery.LockType:=ltReadOnly;
    AQuery.SQL.Clear;
    AQuery.SQL.Add('select Line from LINE_SETTINGS order by line');
    AQuery.Open;

    AQuery.DisableControls;

    Y:=0;

    while not AQuery.Eof do
    begin
      ChefReportLine := TChefReportLine.Create(ChefReport);

      ChefReportLine.Caption:='Linie Nr. '+AQuery.FieldByName('Line').AsString;
      ChefReportLine.FLine:=AQuery.FieldByName('Line').AsInteger;

      ChefReportLine.Top:=Y;
      ChefReportLine.Left:=0;

      Y:=Y+ChefReportLine.Height;


      AQuery.Next;
    end;

  finally
    AQuery.Free;
  end;
end;
user1937012
  • 1,031
  • 11
  • 20
  • The VCL is simply not designed to allow multiple fsMDIForm forms, only the MainForm can be set to fsMDIForm, mainly due to fsMDIChild forms being hard-coded to look only at the MainForm when embedding their window in a fsMDIForm's client area. There are ways to circumvent this limitation, but it requires hacking the VCL sources. – Remy Lebeau Aug 31 '20 at 15:57
  • @Remy : no offense I am nothing compared to you... but this post the answer it works without hacking anything . https://stackoverflow.com/questions/57741216/allow-multiple-mdi-parent-forms-on-same-application . I just used the Code from the MDIChild... and then I was able to ChefReportLine := TChefReportLine.Create(ChefReport); And it works with Delphi 10.3 Rio – user1937012 Aug 31 '20 at 18:26
  • There is more involved with this issue than just getting an `fsMDIChild`'s `HWND` created via `WM_MDICREATE` instead of `CreateWindowEx()`, if you had read my articles and tickets on this subject. A *proper* and *complete* solution involves changes to VCL internals as well. Things like the `fsMDIForm`'s `MDIChildCount`/`MDIChildren[]` properties, `fsMDIChild` menu merging, etc are also affected. Things you can't fix with just `override`s. Getting `WM_MDICREATE` working with a non-MainForm `fsMDIForm` is just the first step, but may be that is enough for you, depending on your particular needs. – Remy Lebeau Aug 31 '20 at 19:34

0 Answers0