tags:

views:

204

answers:

4

I'm trying to assign a ParentWindow, to a control created in a dll. The control is an editor, I need to process a text file, but this control requires a ParentWindow.

How can I solve this problem, if I create this control in a dll?

I'm using Delphi 5.

A: 

also create the TForm (maybe not Visible) inside the dll then the control and add it to the form

luca
it's a good answer, but i resolved sending as argument my form handle into the dll
pythoniso
Then why not provide your solution as an answer and by that possibly help others having similar problems? You could even accept your own anser after a day.
Smasher
A: 

This is a common question, and the correct answer is "Don't do that".

The first question I have is "why do you feel the need to create a control in a DLL?" Why not just create it in code or include the control itself in your EXE?

Second, if you want to add a control to a separate binary, but it in a Package. Packages are designed specifically to make exporting controls simple and easy.

Nick Hodges
Personally I think that's a bit of a silly answer. What if I wanted to use something like a scintilla type of control. I can't embed it in the .exe as it's an external .dll. I could include it as .obj files but that's assuming you have the original src. How about the Mozilla embeddable controls. Why can't I parent something created in a third-party DLL to a Delphi form? Packages are not the end all-be all of exporting controls. I've used packages in the past and wont use them now unless absolutely necessary.
Ryan J. Mills
Well, downvoting it seems a bit much, given that it is technically accurate, and most of the time, putting a Delphi control into a DLL is the /wrong/ thing to do.
Nick Hodges
@Nick: I'm very interested in reading up on the topic of splitting a Delphi application into one main shell application and a number of separate extension packages. Can you suggest a good summary of this subject I could read?
Larry Lustig
Nick Hodges
A: 

You need to get the parent window from somewhere! Typically the host application that loads and calls the DLL would supply a window handle. It looks like your DLL provides a custom control for an application, so of course the application needs to supply a parent window handle.

Also, you typically need a window handle to the entire application as well, which you set as Application.Handle before you do anything else in your DLL.

Frederik Slijkerman
A: 

ok, thaks for your answers, i already solved (a few minutes before first answer).

first, i need explain why i don't embed, and that is because costumer ask me that way.

the solution is send my form handle to my dll as an argument, after testing that way, i got no errors...

only modificate the prototype of my procedure, to recieve a HWND as an argument, to ParentWindow prop of my control (created in memory). that's all.

pythoniso
Nick, your answer is correct, personally i won't do that again if i'm doing a "standalone" app, but you know, costumers change requeriments all the time.Ryan, your point it's correct too, next time i'll ask requeriments first.Smasher, this is the solution, i don't think 'bout others with similar problems.thanks to all.
pythoniso