source: trunk/Packages/Common/FormEx.pas

Last change on this file was 30, checked in by chronos, 6 months ago
  • Modified: Updated Common package.
File size: 2.2 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 protected
16 procedure DoShow; override;
17 procedure DoCreate; override;
18 procedure DoClose(var CloseAction: TCloseAction); override;
19 procedure DoDestroy; override;
20 public
21 PersistentForm: TPersistentForm; static;
22 ThemeManager: TThemeManager; static;
23 Translator: TTranslator; static;
24 ScaleDPI: TScaleDPI; static;
25 OwnsPersistentForm: Boolean; static;
26 OwnsThemeManager: Boolean; static;
27 OwnsTranslator: Boolean; static;
28 OwnsScaleDPI: Boolean; static;
29 end;
30
31procedure Register;
32
33
34implementation
35
36procedure Register;
37begin
38 RegisterNoIcon([TFormEx]);
39end;
40
41{ TFormEx }
42
43procedure TFormEx.DoShow;
44begin
45 inherited;
46 PersistentForm.Load(Self);
47end;
48
49procedure TFormEx.DoCreate;
50begin
51 if not Assigned(PersistentForm) then begin
52 OwnsPersistentForm := True;
53 PersistentForm := TPersistentForm.Create(nil);
54 end;
55 if not Assigned(ThemeManager) then begin
56 OwnsThemeManager := True;
57 ThemeManager := TThemeManager.Create(nil);
58 end;
59 if not Assigned(Translator) then begin
60 Translator := TTranslator.Create(nil);
61 Translator.POFilesFolder := 'Languages';
62 Translator.Language := Translator.Languages.SearchByCode('');
63 OwnsTranslator := True;
64 end;
65 if not Assigned(ScaleDPI) then begin
66 OwnsScaleDPI := True;
67 ScaleDPI := TScaleDPI.Create(nil);
68 end;
69
70 Translator.TranslateComponentRecursive(Self);
71 ThemeManager.UseTheme(Self);
72 Inc(FCounter);
73 inherited;
74end;
75
76procedure TFormEx.DoClose(var CloseAction: TCloseAction);
77begin
78 PersistentForm.Save(Self);
79 inherited;
80end;
81
82procedure TFormEx.DoDestroy;
83begin
84 Dec(FCounter);
85 if FCounter <= 0 then begin
86 if OwnsPersistentForm then begin
87 FreeAndNil(PersistentForm);
88 OwnsPersistentForm := False;
89 end;
90 if OwnsThemeManager then begin
91 FreeAndNil(ThemeManager);
92 OwnsThemeManager := False;
93 end;
94 if OwnsTranslator then begin
95 FreeAndNil(Translator);
96 OwnsTranslator := False;
97 end;
98 if OwnsScaleDPI then begin
99 FreeAndNil(ScaleDPI);
100 OwnsScaleDPI := False;
101 end;
102 end;
103 inherited;
104end;
105
106end.
107
Note: See TracBrowser for help on using the repository browser.