Solved

Creating Form with only a handle

Posted on 1997-04-27
9
162 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Strange code, can use it, but i cant figure out what it does. 3 66
Intraweb download file link ? 1 155
Delphi 2 69
DBCtrlGrid, Delphi, Scroll 8 37
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

856 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