...create a parented control in a DLL?
|[ Print tip
]|| || |
// In DLL
// This is our windowed control, which also
// contains more windowed controls within itself
TMyPanel = class(TPanel)
constructor Create(aOwner: TComponent); override;
// Initialize properties here
constructor TMyPanel.Create(aOwner: TComponent);
// This method adds this control to its parent
// and initializes and adds its own controls
// Now, here we have to set ParentWindow,
// because this control is in a DLL.
// Doing it otherwise will cause "Control
// has no parent window" error.
// We do it before we assign Parent (if we)
// assign Parent first, the assignment
// to ParentWindow will have no effect.
// After these two assignments, our
// control is contained within its parent
// so, we setup the parent dependant
// properties now, such as align
Self.ParentWindow := TWinControl(Owner);
Self.Parent := TWinControl(Owner);
Self.Align = alLeft;
...fSomeControl := TMyWinControl.Create(Self);
fSomeControl.ParentWindow := Self.Handle;
fSomeControl.Parent := Self;
fSomeControl.Align := alTop;
// init more properties
// In application
...MyPanel := TMyPanel.Create(Form1);
// Note that if we created the TMyPanel object in
// DLL (e.g. with a call to a function that
// returned the object), we should destroy it
// in DLL, too, to avoid the access violation.