Solved

Creating Form with only a handle

Posted on 1997-04-27
9
158 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

770 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