sheldon040297
asked on
Creating Form with only a handle
I wish to create a form in a DLL, calling the DLL from another application. To create the form, I must pass anowner, which is of type TComponent, but I only have thehandle of the parent.e.g. in DLLprocedure CreateNewWindow(ParentHand le : HWnd);begin ?????? Form1 := TForm1.Create(??????);end; If anyone understands what I am actually trying to askhere, could they also supply an answer please.Thanks
Why not just create the window and send it to the DLL ?
ASKER
Edited text of question
ASKER
The calling application is not a Delphi application. It is a GIStool called ArcView. The application supplies the handle tothe main window, but this is all. I can create a child windowfor the application in Delphi by using the Windows API only, but I would rather use the VCL to make it easier to add different elements.
Pass parent handle as nil (but you must be sure you will destroy it once application terminates). In your form overwrite CreateParams method.
procedure MyForm.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.WndParent := Handle you have from another app;
end;
Tha should do it.
procedure MyForm.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.WndParent := Handle you have from another app;
end;
Tha should do it.
ASKER
I need more info. I couldn't get that to work at all.
What did it do ?
How about creating the window in delphi but not showing it. In this way you can use the API call showwindow to "create" it by actually painting it on the screen ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I just read my answer to you again... sorry, its not very clear.
In the dll:
PROCEDURE ShowMy Form; Export;
VAR ff: TMyForm; {this must be here.. not global}
BEGIN
TRY
ff := TMyForm.Create( NIL );
TRY
ff.ShowModal; {must be modal}
FINALLY
ff.Free;
END;
EXCEPT
ON Exception DO {whatever you want} ;
END;
END;
Hope this is more clear.
In the dll:
PROCEDURE ShowMy Form; Export;
VAR ff: TMyForm; {this must be here.. not global}
BEGIN
TRY
ff := TMyForm.Create( NIL );
TRY
ff.ShowModal; {must be modal}
FINALLY
ff.Free;
END;
EXCEPT
ON Exception DO {whatever you want} ;
END;
END;
Hope this is more clear.