• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 573
  • Last Modified:

Delphi MDI Application

I am developing an MDI Application and I would like to have a DBNavigator on my main form (fsmdiform). The component is placed on the main toolbar. I would like the DBNavigator to get the ActiveMDIChild form and if it has a Datasource component the DBNavigator's.Datasource property should be set to the one of the fsmdichild. This should change if the active mdi child changes.
0
mc94051
Asked:
mc94051
  • 2
1 Solution
 
jpedefCommented:
Create ApplicationIdle event and check activemdichild, then search for datasource.

In Main forms private section add
  LastActive: TForm;

In MainFormCreate event
Application.OnIdle := AppIdle;

procedure TForm1.AppIdle(Sender: TObject; var Done: Boolean);
var
  AForm: TForm;
  i: integer;
begin
  AForm := ActiveMDIChild;
  if AForm = LastActive then
    Exit;
  if AForm = nil then
    DBNavigator1.DataSource := nil
  else
    for i := 0 to AForm.ComponetCount - 1 do
    begin
      if AForm.Components[i] is TDataSource then
      begin
        DBNavigator1.DataSource := TDataSource(AForm.Components[i]);
        Break;
      end;
    end;
end;

I didn't test this, but at least it shold give you an idea about it.
0
 
jpedefCommented:
OK let's correct AppIdle procedure a bit.

procedure TForm1.AppIdle(Sender: TObject; var Done: Boolean);
var
  AForm: TForm;
  i: integer;
begin
  AForm := ActiveMDIChild;
  if AForm = LastActive then
    Exit; //** To avoid repetition
  LastActive := AForm;
  if AForm = nil then
    DBNavigator1.DataSource := nil
  else
    for i := 0 to AForm.ComponetCount - 1 do
    begin
      if AForm.Components[i] is TDataSource then
      begin
        DBNavigator1.DataSource := TDataSource(AForm.Components[i]);
        Break;
      end;
    end;
end;
0
 
mc94051Author Commented:
Thanks very much for the answer, we are almost there I think. I knew the bit with the LastActive Form, checking for the Datasource and casting it to assign it to my DBNavigator my main concern is the event I should use. AppIdle does work when the child forms are created but when I have one form open and then I activate another child it doesn't work. Is there another better event to accomplish this?
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now