Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to Create and Manage Modal and Modeless forms in a DLL Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
30-Jun-03
Category
VCL-Forms
Language
Delphi 2.x
Views
162
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Manuel Sarmiento

Displaying and using forms from a DLL can be difficult if you don't know the way. 
Fortunately enough, Delphi is quite flexible and the managing forms from a DLL is 
quite easy.

Answer:

The first thing you will need a Handle to the application’s main window. Assuming 
that the application is running on top, you can get the window’s handle using 
GetActiveWindow, like this: 

MainApplicationHandle := GetActiveWindow;

In order to be able to take advantage of Delphi’s window controlling features, 
however, you need a window control, not a window handle. You can get a window 
control uising FindControl (Controls Unit) 
1   
2   fWinControl := FindControl(MainApplicationHandle);


fWinControl is assumed to be of TwinControl type.. 

I have found it useful to create the Modal (or modeless window) since the 
begiinning: 
3   
4   MyForm := TMyForm.create(fWinControl);


The three items can be placed confortably in the initialization section of the DLL: 

5   MainApplicationHandle := GetActiveWindow;
6   fWinControl := FindControl(MainApplicationHandle);
7   MyForm := TMyForm.create(fWinControl);


Finally, when you need the Form, you just show it, but be carfeul to redraw it if 
something changed within it: 

8   MyForm.Repaint;
9   winresult := MyForm.showmodal


(winresult is defined to be of typo longint) You just have to be sure that your 
form includes wither buttons that produce a modal result (by setting ModalResult to 
something else than mrNone) 
If you’d rather prefer a modeless window (for example, to display a progress bar) , 
you can use the following approach: 

10  MyForm.Visible := true;
11  while {some condition set} do
12  begin
13    {change something in the window}
14    MyForm.repaint;
15  end;
16  MyForm.Hide;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC