Notice Of Closure

Please note that this website is due to close down on 15th June 2020.

In the interim I will try to move as much content as possible over to my GitHub account. Thanks to everyone who has supported the site over the years.

» Help

How to subclass the default Delphi Dock Manager


After a lot of trial and error, I finally figured out how to properly subclass the default Delphi Dock Manager so that you can take control of how the docked controls / forms look. Here are the details.

First, create your own dock manager implementation, inheriting from the Delphi default, for e.g.:

  Windows, Graphics, Controls;
  TMyDockTree = class(TDockTree)
    procedure PaintDockFrame(Canvas: TCanvas; Control: TControl;
      const ARect: TRect); override;

In this case, I want to override the drawing behavior, so I will supply my own PaintDockFrame routine. But you can override any of the default methods that you want.

OK, now, here is the trick. The control that you want to dock into (like a TPanel), needs to have the UseDockManager property in the Object Inspector set to False. Then, in the FormCreate routine, you assign your custom dock manager to the control and only then turn the UseDockManager property on:

procedure TForm1.FormCreate(Sender: TObject);
  Panel1.DockManager := TMyDockTree.Create( Panel1);
  Panel1.UseDockManager := true;

In this case, I'm using a TPanel as my dock site. The DockSite property of the panel is turned on in the object inspector.

That's it! The trick was turning off UseDockManager to avoid Delphi assigning the default dock manager, and turning it on manually in the form creator.

Original resource: The Delphi Pool
Author: Mike Potter
Added: 2012-07-08
Last updated: 2012-07-08

« Return to contents »