Creating controls on main form from a DLL
Posted on 1997-09-04
I have a situation where I need to create objects on the main applications form (or a panel) from inside a DLL. When I create a button in the manner described below, I experience these 3 problems:
1) the button is not displayed until I make the panel invisible then visible again
2) If I TAB to teh button, I generate the 'EInvalid Operation' exception with the message 'Control 'BB' has no parent window'
3) The object will not get destroyed when the application exits
The prime area of my concern is the second one. The strange thing is that if I use EXACTLY the same code inside the main application, none of these problems are evident!
I have drilled down through the Parent panels properties to compare all properties of the button and compared them to when it is created from inside teh main application, and can find no significant variation. In particular, the button's FParent property is set to the Panel!
Here is the code which I used inside the DLL to create the button:
procedure MakePB( UserOutput:TWinControl ); stdcall;
BB := TButton.Create( UserOutput );
with UserOutput.ClientRect do begin
BB.Left := Left + 5;
BB.Top := Top + 35;
BB.Font.Style := ;
BB.Font.Size := 10;
BB.Parent := UserOutput;
BB.Caption := 'A PB';
BB.Name := 'A_PB';
This function is called like this:
procedure TForm1.Button3Click(Sender: TObject);
(Note: The nature of my application is such that I can't create a Form inside the DLL for the button ...)