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 only one instance of a MDI child form (4) 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-Aug-02
Category
Others
Language
Delphi All Versions
Views
66
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

What is the best way to avoid a form being created more than once in a MDI 
application?

Answer:

1   unit WindowFunctions;
2   
3   interface
4   
5   uses
6     Classes, Forms;
7   
8   function IsChildWindow(AFormClass: TFormClass; AiTag: integer): Boolean;
9   procedure CreateChildWin(AOwner: TComponent; AFormClass: TFormClass; AiTag: 
10  integer);
11  
12  implementation
13  
14  uses
15    Dialogs, Controls;
16  
17  function IsChildWindow(AFormClass: TFormClass; AiTag: integer): boolean;
18  var
19    i: integer;
20  begin
21    Result := False; {The window does not exist}
22    for i := 0 to (Screen.FormCount - 1) do
23    begin
24      if (Screen.Forms[i] is AFormClass) and (AiTag = Screen.Forms[i].Tag) then
25      begin
26        {The window was found}
27        Screen.Forms[i].BringToFront;
28        Result := True;
29        break;
30      end;
31    end;
32  end;
33  
34  procedure CreateChildWin(AOwner: TComponent; AFormClass: TFormClass; AiTag: 
35  integer);
36  begin
37    if not IsChildWindow(AFormClass, AiTag) then
38    begin
39      with AFormClass.Create(AOwner) do
40      begin
41        Tag := AiTag;
42      end;
43    end;
44  end;
45  
46  end.


			
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