Howdy, Stranger!

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

In this Discussion

How to ensure objects in a Tabbed Dock panel have closed before opening the next doc TabbedPanel.

I am using Tabbed docs to hold a number of editor pages. When I close the a tab I want the document to close and the next lower tab to be selected.  By default, after closing a tab the selected first tab is selected which is not necessarily the one adjacent to the tab being closed.  I use a routine which selects the previous tab based on a routine you suggested in an earlier query.  This is the procedure.

procedure TfmIDEMain.SelectPrevTab;
Var dz,tz, prevz: TLMDDockZone;
    dp: TLMDDockPanel;
    i: Integer;
  if Assigned(ActivePanel) then begin
    Application.ProcessMessages;  // Give time for last ppage to close
    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];
        tz.SelectedPage := prevz;
        if Assigned(tz)
        and (tz.SelectedPage.Panel.ClientKind = dkDocument) then begin
          ActivePanel := tz.SelectedPage.Panel;
          case TIDEPageType(ActivePanel.tag) of
            ptEditor:  TfmEditor(ActivePanel.Controls[0]).DocEnter(self);
            ptPDF: TfmPDFPage(ActivePanel.Controls[0]).DocEnter(self);

The problem I have is that if I call this routine from my DocClose event it activates the previous panel before has been able to close.  By removing the highlighted DocEnter from the SelectPrevTab routine I can set the new active panel before the document has closed. How can I call the appropriate DocEnter after the document is closed? The only way I can think of doing it is to fire a  timer off on the main form which allows sufficient time for the closing document to complete the closure before calling ActivePanel.DocEnter Is there a better way?


  • 1 Comment sorted by Votes Date Added
  • I cannot understand why you need to activate previous tab after closing the current one? The best way, which eliminates possible UI flickering, is to activate it before, and then close already invisible current tab. 
    I suggest you to find and activate appropriate tab before closing some other tabs.

    As about Timer - this will work. You can set timer interval to some minimum value, for example, 1. Timer works asynchronously, using Windows message loop, so, its OnTimer will not occures before your document is fully closed. 
Sign In or Register to comment.