Solved

Creating Form with only a handle

Posted on 1997-04-27
9
150 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
 

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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

707 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now