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 make a form use two frames in separate units 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
03-Jan-03
Category
VCL-General
Language
Delphi 2.x
Views
49
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Lou Adler

How can I make a function which will create a frame (given its class) in a new form?

Answer:

Maybe you should use an enumerated value which is an index of an array of your 
frame classes. An example with a form using two frames in seperate units:

1   unit UnitTestForm;
2   
3   interface
4   
5   uses
6     Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7     Dialogs, StdCtrls, UnitFrameOne, UnitFrameTwo;
8   
9   type
10    {'class of' and enumeration}
11    TFrameClass = class of TFrame;
12    TFrameEnm = (frm_one, frm_two);
13  
14    {array of classes}
15    TFrameClasses = array[TFrameEnm] of TFrameClass;
16  
17    {test form}
18    TForm1 = class(TForm)
19      btnCreateFrame1: TButton;
20      btnCreateFrame2: TButton;
21      procedure btnCreateFrame1Click(Sender: TObject);
22      procedure btnCreateFrame2Click(Sender: TObject);
23    private
24      function CreateFrame(FrameEnm: TFrameEnm): TForm;
25    public
26    end;
27  
28  var
29    Frames: TFrameClasses = (TFrameOne, TFrameTwo);
30  
31    Form1: TForm1;
32  
33  implementation
34  
35  {$R *.dfm}
36  
37  procedure TForm1.btnCreateFrame1Click(Sender: TObject);
38  var
39    Form: TForm;
40  begin
41    Form := Self.CreateFrame(frm_one);
42    Form.ShowModal;
43  end;
44  
45  procedure TForm1.btnCreateFrame2Click(Sender: TObject);
46  var
47    Form: TForm;
48  begin
49    Form := Self.CreateFrame(frm_two);
50    Form.ShowModal;
51  end;
52  
53  function TForm1.CreateFrame(FrameEnm: TFrameEnm): TForm;
54  var
55    aFrame: TFrame;
56  begin
57    Result := TForm.Create(nil);
58    aFrame := Frames[FrameEnm].Create(Result);
59    aFrame.Parent := Result;
60    aFrame.Align := alClient;
61  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