If a descendent of TCustomControl is dynamically created on a TLMDDockPanel then dynamically freed then it can cause a crash due to the control's canvas being accessed after it has been destroyed.
There seem to be some essential pre-conditions.
1. The control initially does not have focus.
2. In the event handler that causes the control to be destroyed, the control is briefly given focus just before it is destroyed. In my test case this is caused by a ShowMessage call (e.g. to ask user confirmation) but FocusControl(fControl) also has the same effect.
The crash occurs only if a TLMDDockPanel is a parent of the control. It doesn't occur with a regular TPanel or if the control is a direct child of TForm. This is why I think the fault is in TLMDDockPanel.
Unfortunately I can't seem to upload a zip file containing the test case, so here it is:
Winapi.Windows, Winapi.Messages, System.Classes, Vcl.Controls, Vcl.Forms,
TMyControl = class (TCustomControl)
procedure CMFocusChanged(var Message: TCMFocusChanged); message CM_FOCUSCHANGED;
constructor Create(AOwner: TComponent); override;
TForm1 = class(TForm)
procedure CrashMenuItemClick(Sender: TObject);
procedure FormShow(Sender: TObject);
fControl : TMyControl;
procedure WMUser(var aMsg: TMessage); message WM_USER;
constructor TMyControl.Create(AOwner: TComponent);
Width := 75;
Height := 25;
TabStop := True;
procedure TMyControl.CMFocusChanged(var Message: TCMFocusChanged);
procedure TForm1.CrashMenuItemClick(Sender: TObject);
procedure TForm1.FormShow(Sender: TObject);
PostMessage(Handle, WM_USER, 0, 0);
procedure TForm1.WMUser(var aMsg: TMessage);
fControl := TMyControl.Create(LMDDockPanel1);
fControl.Parent := LMDDockPanel1;
fControl.Top := 23;
You'll have to drop a TLMDDockSite on the form, add a TLMDDockPanel, and also a TMainMenu with a single menu item that invokes CrashMenuItemClick. Run the application, then without clicking on anything else, invoke the Crash menu item. Dismiss the dialog, and you should get an access violation.
I'm using TLMDTools 2013, update 3. Is this problem fixed in the latest version? If not, will you fix it and if so when?