source: trunk/Packages/Common/FormEx.pas

Last change on this file was 593, checked in by chronos, 3 months ago
  • Modified: Updated Common package.
File size: 2.5 KB
Line 
1unit FormEx;
2
3interface
4
5uses
6 Classes, SysUtils, Forms, PersistentForm, Theme, Translator, ScaleDPI;
7
8type
9
10 { TFormEx }
11
12 TFormEx = class(TForm)
13 private
14 FCounter: Integer; static;
15 FFirstShow: Boolean;
16 protected
17 procedure DoShow; override;
18 procedure DoCreate; override;
19 procedure DoClose(var CloseAction: TCloseAction); override;
20 procedure DoDestroy; override;
21 public
22 FullScreen: Boolean;
23 PersistentForm: TPersistentForm; static;
24 ThemeManager: TThemeManager; static;
25 Translator: TTranslator; static;
26 ScaleDPI: TScaleDPI; static;
27 OwnsPersistentForm: Boolean; static;
28 OwnsThemeManager: Boolean; static;
29 OwnsTranslator: Boolean; static;
30 OwnsScaleDPI: Boolean; static;
31 end;
32
33procedure Register;
34
35
36implementation
37
38procedure Register;
39begin
40 RegisterNoIcon([TFormEx]);
41end;
42
43{ TFormEx }
44
45procedure TFormEx.DoShow;
46begin
47 inherited;
48 if not FFirstShow and (not (csDesigning in ComponentState)) then begin
49 FFirstShow := True;
50 PersistentForm.Load(Self);
51 FullScreen := PersistentForm.FormFullScreen;
52 end;
53end;
54
55procedure TFormEx.DoCreate;
56begin
57 if not Assigned(PersistentForm) then begin
58 OwnsPersistentForm := True;
59 PersistentForm := TPersistentForm.Create(nil);
60 end;
61 if not Assigned(ThemeManager) then begin
62 OwnsThemeManager := True;
63 ThemeManager := TThemeManager.Create(nil);
64 end;
65 if not Assigned(Translator) then begin
66 Translator := TTranslator.Create(nil);
67 Translator.POFilesFolder := 'Languages';
68 Translator.Language := Translator.Languages.SearchByCode('');
69 OwnsTranslator := True;
70 end;
71 if not Assigned(ScaleDPI) then begin
72 OwnsScaleDPI := True;
73 ScaleDPI := TScaleDPI.Create(nil);
74 end;
75
76 Translator.TranslateComponentRecursive(Self);
77 ThemeManager.UseTheme(Self);
78 Inc(FCounter);
79 inherited;
80end;
81
82procedure TFormEx.DoClose(var CloseAction: TCloseAction);
83begin
84 if (not (csDesigning in ComponentState)) then begin
85 PersistentForm.FormFullScreen := FullScreen;
86 PersistentForm.Save(Self);
87 end;
88 inherited;
89end;
90
91procedure TFormEx.DoDestroy;
92begin
93 Dec(FCounter);
94 if FCounter <= 0 then begin
95 if OwnsPersistentForm then begin
96 FreeAndNil(PersistentForm);
97 OwnsPersistentForm := False;
98 end;
99 if OwnsThemeManager then begin
100 FreeAndNil(ThemeManager);
101 OwnsThemeManager := False;
102 end;
103 if OwnsTranslator then begin
104 FreeAndNil(Translator);
105 OwnsTranslator := False;
106 end;
107 if OwnsScaleDPI then begin
108 FreeAndNil(ScaleDPI);
109 OwnsScaleDPI := False;
110 end;
111 end;
112 inherited;
113end;
114
115end.
116
Note: See TracBrowser for help on using the repository browser.