Sign in Join
Wiki copytemporary

Frames: what changed

Revision 2 to 3. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
1-**[[TFrame|TFrames]]** are named containers for components and very similar to [[TForm|forms]]. Their unique ability is that they can be embedded into forms or other frames in the designer. As forms they are stored in two files: the code is stored in .pas file and the design in the .lfm file.
2-
3-## How to create a frame?
4-
5-Press File-\>New... menu item and in the opened dialog select "Frame" item.
6-
7-![](/wiki-images/6/6d/Frame_new.PNG)
8-
9-## How to place a frame to the form or another frame?
10-
11-The [[Standard tab]] of the [[Component Palette]] has a special component item "[[TFrame]]". When you drop it to the form or frame the IDE asks you to choose one of project frames. You have to save the project and the the new frame first, only saved frames will appear in the choose from list. Frames in packages are not yet implemented. But you can create frames in code even in packages. You can't create frame circles - the IDE will forbid this, i.o.w. you can't place FrameA to FrameA and you can't place any frame which contains FrameA to FrameA.
12-
13-![](/wiki-images/3/35/Frame_add.PNG)
1+**[[TFrame|TFrames]]** are named containers for components and very similar to [[TForm|forms]]. Their unique ability is that they can be embedded into forms or other frames in the designer. As forms they are stored in two files: the code is stored in .pas file and the design in the .lfm file.
142
153## What can they be used for?
164
17-They are needed when you have a group of components that you want to reuse on multiple forms. The group should have the same set of controls and logic between them at different windows (forms) of your application. You can group that repeated controls and logic into one frame and use that frame in different places. Therefore you don't need to repeat the work of control layouting and writing their logic.
5+They are needed when you have a group of components that you want to reuse on multiple forms. The group should have the same set of controls and logic between them at different windows (forms) of your application. You can group that repeated controls and logic into one frame and use that frame in different places. Therefore you don't need to repeat the work of control layouting and writing their logic.
186
19-For example, you have two listboxes and buttons to move items between them. So you can create a frame with two listboxes and needed buttons, write the logic for items moving and then use your frame on all forms where needed. Moreover, if you find an error in the frame code then you can fix it once in the frame code instead of fixing it n-times among all forms.
7+For example, you have two listboxes and buttons to move items between them. So you can create a frame with two listboxes and needed buttons, write the logic for items moving and then use your frame on all forms where needed. Moreover, if you find an error in the frame code then you can fix it once in the frame code instead of fixing it n-times among all forms.
208
21-a frame in designer:
9+a frame in designer:
2210
23-![](/wiki-images/1/13/Frame_example.PNG)
11+[![Frame example.PNG](/wiki-images/1/13/Frame_example.PNG)](</File:Frame_example.PNG>)
2412
25-the frame placed on a form:
13+
14+the frame placed on a form:
2615
27-![](/wiki-images/d/d4/Frame_embedded.PNG%E2%80%8E)
16+[![Frame embedded.PNG](/wiki-images/1/17/Frame_embedded.PNG)](</File:Frame_embedded.PNG>)
2817
29-the same frame placed on another form:
18+the same frame placed on another form:
3019
31-![](/wiki-images/3/36/Frame_embedded2.PNG%E2%80%8E)
20+[![Frame embedded2.PNG](/wiki-images/8/88/Frame_embedded2.PNG)](</File:Frame_embedded2.PNG>)
3221
3322## Initialising private variables
3423
35-TFrame does not have OnCreate or OnDestroy events in which private variables can be initialised and released. [[Override]] the default [[Constructor|constructor]] and [[Destructor|destructor]] to do this.
36-
37-``` pascal
24+TFrame does not have OnCreate or OnDestroy events in which private variables can be initialised and released. [[Override]] the default [[Constructor|constructor]] and [[Destructor|destructor]] to do this.
25+```
3826TFrame1 = class(TFrame)
39- private
40- MyObj: TObject;
41- public
42- constructor Create(TheOwner: TComponent); override;
43- destructor Destroy; override;
44- end;
45-
46-constructor TFrame1.Create(TheOwner: TComponent);
47-begin
48- inherited Create(TheOwner);
49- MyObj := TObject.Create;
50-end;
51-
52-destructor TFrame1.Destroy;
53-begin
54- MyObj.Free
55- inherited Destroy;
56-end;
27+ private
28+ MyObj: TObject;
29+ public
30+ constructor Create(TheOwner: TComponent); override;
31+ destructor Destroy; override;
32+ end;
33+
34+ constructor TFrame1.Create(TheOwner: TComponent);
35+ begin
36+ inherited Create(TheOwner);
37+ MyObj := TObject.Create;
38+ end;
39+
40+ destructor TFrame1.Destroy;
41+ begin
42+ MyObj.Free
43+ inherited Destroy;
44+ end;
5745```
5846
5947## Sample of dynamic creation
6048
61-More easy. Because TFrame component in component palette is not required. And you can make a page change type application(like a smart phone application) with save resource.
62-
63-``` pascal
49+More easy. Because TFrame component in component palette is not required. And you can make a page change type application(like a smart phone application) with save resource.
50+```
6451unit Unit1;
65-
66-{$mode objfpc}{$H+}
67-
68-interface
69-
70-uses
71- Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;
72-
73-type
74-
75- { TForm1 }
76-
77- TForm1 = class(TForm)
78- Button1: TButton;
79- GroupBox1: TGroupBox;
80- procedure Button1Click(Sender: TObject);
81- procedure FormCreate(Sender: TObject);
82- private
83- { private declarations }
84- Frame: TFrame;
85- public
86- { public declarations }
87- end;
88-
89-var
90- Form1: TForm1;
91-
92-implementation
93-uses
94- Unit2{TFrame1}, Unit3{TFrame2}, Unit4{TFrame3};
95-
96-{$R *.lfm}
97-
98-{ TForm1 }
99-
100-procedure TForm1.FormCreate(Sender: TObject);
101-begin
102- Frame := TFrame1.Create(GroupBox1);
103- Frame.Parent := GroupBox1;
104-end;
105-
106-procedure TForm1.Button1Click(Sender: TObject);
107-begin
108- if not Assigned(Frame) then
109- begin
110- Frame := TFrame1.Create(GroupBox1);
111- Frame.Parent := GroupBox1;
112- end else if Frame is TFrame1 then begin
113- Frame.Free;
114- Frame := TFrame2.Create(GroupBox1);
115- Frame.Parent := GroupBox1;
116- end else if Frame is TFrame2 then begin
117- Frame.Free;
118- Frame := TFrame3.Create(GroupBox1);
119- Frame.Parent := GroupBox1;
120- end else begin
121- FreeAndNil(Frame);
122- end;
123-end;
124-
125-end.
52+
53+ {$mode objfpc}{$H+}
54+
55+ interface
56+
57+ uses
58+ Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;
59+
60+ type
61+
62+ { TForm1 }
63+
64+ TForm1 = class(TForm)
65+ Button1: TButton;
66+ GroupBox1: TGroupBox;
67+ procedure Button1Click(Sender: TObject);
68+ procedure FormCreate(Sender: TObject);
69+ private
70+ { private declarations }
71+ Frame: TFrame;
72+ public
73+ { public declarations }
74+ end;
75+
76+ var
77+ Form1: TForm1;
78+
79+ implementation
80+ uses
81+ Unit2{TFrame1}, Unit3{TFrame2}, Unit4{TFrame3};
82+
83+ {$R *.lfm}
84+
85+ { TForm1 }
86+
87+ procedure TForm1.FormCreate(Sender: TObject);
88+ begin
89+ Frame := TFrame1.Create(GroupBox1);
90+ Frame.Parent := GroupBox1;
91+ end;
92+
93+ procedure TForm1.Button1Click(Sender: TObject);
94+ begin
95+ if not Assigned(Frame) then
96+ begin
97+ Frame := TFrame1.Create(GroupBox1);
98+ Frame.Parent := GroupBox1;
99+ end else if Frame is TFrame1 then begin
100+ Frame.Free;
101+ Frame := TFrame2.Create(GroupBox1);
102+ Frame.Parent := GroupBox1;
103+ end else if Frame is TFrame2 then begin
104+ Frame.Free;
105+ Frame := TFrame3.Create(GroupBox1);
106+ Frame.Parent := GroupBox1;
107+ end else begin
108+ FreeAndNil(Frame);
109+ end;
110+ end;
111+
112+ end.
126113```
127114
128115## See also
129116
130-- [[TFrame]]
117+ * [[TFrame]]
131118
132119---
133-*From the Free Pascal wiki, page "Frames", as it stood on 2020-05-12 after a change by Jesusrmx, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
120+*From the Free Pascal wiki, page "Frames", as the Internet Archive kept it on 2024-12-07, last changed on 2024-11-18. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history