Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Creating Form with only a handle

Posted on 1997-04-27
9
Medium Priority
?
185 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
Independent Software Vendors: 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 200 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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
Integration Management Part 2
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

810 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