whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

23 Visitors Online


 
...create a parented control in a DLL?
Autor: Lüpher Cypher
[ Print tip ]  

Tip Rating (15):  
     


// In DLL
//
// This is our windowed control, which also
// contains more windowed controls within itself

type
TMyPanel = class(TPanel)
fSomeControl: tMyWinControl;

constructor Create(aOwner: TComponent); override;
procedure updateControls();
end;...

// Initialize properties here
constructor TMyPanel.Create(aOwner: TComponent);
begin
inherited
Create(aOwner);
...end;

// This method adds this control to its parent
// and initializes and adds its own controls
procedure TMyPanel.updateControls();
begin
// 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
...end;


// In application
//

...MyPanel := TMyPanel.Create(Form1);

MyPanel.updateControls();

// 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.


 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners