Solved

Creating Form with only a handle

Posted on 1997-04-27
9
165 Views
Last Modified: 2010-04-04
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(ParentHandle : HWnd);begin  ??????  Form1 := TForm1.Create(??????);end;If anyone understands what I am actually trying to askhere, could they also supply an answer please.Thanks
0
Comment
Question by:sheldon040297
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 1

Expert Comment

by:miv
ID: 1335747
Why not just create the window and send it to the DLL ?
0
 

Author Comment

by:sheldon040297
ID: 1335748
Edited text of question
0
 

Author Comment

by:sheldon040297
ID: 1335749
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.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:lkovac
ID: 1335750
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.
0
 

Author Comment

by:sheldon040297
ID: 1335751
I need more info.  I couldn't get that to work at all.
0
 

Expert Comment

by:lkovac
ID: 1335752
What did it do ?
0
 
LVL 2

Expert Comment

by:gysbert1
ID: 1335753
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 ?
0
 
LVL 2

Accepted Solution

by:
icampbe1 earned 100 total points
ID: 1335754
No problem,  In the dll, create a new form (from tool bar) this will result in a new entry in the USES clause of the dll.  Now, remove the global instance variable for the form in the new unit: ie   VAR  Form1: TForm1.  (this can't be a dll global.. otherwise you'll have problems with concurrent calls to the form.)
Now.. Write a procedure, it may as well be the one you export to the external caller, the creates the form with a local instance variable.  VAR ff:TForm (or the Type of your descendant).
Then  ff := TformWhatever.Create( NIL );  This creates the form.
Now, it must be shown MODALLY!!   ff.ShowModal;
When the Form closes, free the instance  ff.free;   Finally, wrap all of this up in a TRY EXCEPT block so errors dont escape the dll.

This is my first answer ever here on the exchange... hope I helped you.. I clarify if you need help.

0
 
LVL 2

Expert Comment

by:icampbe1
ID: 1335755
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.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question