Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

Would Like an Event when a user tabs to a different doc tab

I have a number of Tabbed Docs open.  When user moves from Tab to Tab is it possible to raise an event when the tab change has taken place with the new tab being passed in the event.  Since these changes don't seem to happen in the main thread the only way I have of detecting user has changed tabs is when the user clicks on the new document.



  • 4 Comments sorted by Votes Date Added
  • All DockingPack code works in the main thread. There is TLMDDockSite.OnChange event, which should be fired when the layout is changed in any way, including the case when the user selects another tab. A reference to the current selected doc zone can be retrieved via:

    pnl := MySite.SpaceZone.SelectedPage.Panel;
  • If I use the code above I just get an Access Violation.  This is my code.

    procedure TfmIDEMain.dsMainChange(Sender: TObject);
    var pnl: TLMDDockPanel;
      if Assigned(dsMain.SpaceZone) then begin
        ActivePanel := dsMain.SpaceZone.SelectedPage.Panel;
        if Assigned(ActivePanel) then
          if TIDEPageType(ActivePanel.Tag) = ptEditor then

    The Access Violation happens on start up even if there are no documents being opened. The occurs on the highlighted line.

    The problem I'm trying to resolve only occurs when I am closing a tab.  If I click on the Close button on the tab the tab closes and calls the following routine:

    procedure TfmIDEMain.SelectPrevTab;
    Var dz,tz, prevz: TLMDDockZone;
        dp: TLMDDockPanel;
        i: Integer;
      if Not MultifileLoad
      and Assigned(ActivePanel) then begin
        dp := ActivePanel;
        ActivePanel := nil;
        dz :=;
        if Assigned(dz) then begin
          i := dz.Index;
          tz := dz.parent;
          if Assigned(tz) and (i > 1) then begin
            prevz := tz[i-1];
            if Not prevz.IsEmpty then begin
              tz.SelectedPage := prevz;
              ActivePanel := tz.Panel;

    This then goes to the next open tab but the DocEnter for the new tab doesn't get triggered.  

    If I write code to trigger DocEnter the panel returned from tz.SelectedPage is nil so I cannot access the DocEnter routine of the control.  
    I assume this is because the switch hasn't taken place yet. 

    So if I could get the code you suggested in your original reply to work without crashing using the DockSite OnChange event I would hope that this would solve the problem. 
  • The code was only an example. In reality you should check all referenced objects for null:

    MySite.SpaceZone <> nil
    MySite.SpaceZone.SelectedPage <> nil
    MySite.SpaceZone.SelectedPage.Panel <> nil

  • Thanks, I assumed that the if the highest level was unassigned then every thing below would have been unassigned.
    It now works very well as I don't need to assign DocClose in my CreateNewTab routine.
Sign In or Register to comment.