1 | unit FormEx;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, Forms, PersistentForm, Theme, Translator, ScaleDPI;
|
---|
7 |
|
---|
8 | type
|
---|
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 |
|
---|
31 | procedure Register;
|
---|
32 |
|
---|
33 |
|
---|
34 | implementation
|
---|
35 |
|
---|
36 | procedure Register;
|
---|
37 | begin
|
---|
38 | RegisterNoIcon([TFormEx]);
|
---|
39 | end;
|
---|
40 |
|
---|
41 | { TFormEx }
|
---|
42 |
|
---|
43 | procedure TFormEx.DoShow;
|
---|
44 | begin
|
---|
45 | inherited;
|
---|
46 | PersistentForm.Load(Self);
|
---|
47 | end;
|
---|
48 |
|
---|
49 | procedure TFormEx.DoCreate;
|
---|
50 | begin
|
---|
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 | PersistentForm.Load(Self);
|
---|
71 | Translator.TranslateComponentRecursive(Self);
|
---|
72 | ThemeManager.UseTheme(Self);
|
---|
73 | Inc(FCounter);
|
---|
74 | inherited;
|
---|
75 | end;
|
---|
76 |
|
---|
77 | procedure TFormEx.DoClose(var CloseAction: TCloseAction);
|
---|
78 | begin
|
---|
79 | PersistentForm.Save(Self);
|
---|
80 | inherited;
|
---|
81 | end;
|
---|
82 |
|
---|
83 | procedure TFormEx.DoDestroy;
|
---|
84 | begin
|
---|
85 | Dec(FCounter);
|
---|
86 | if FCounter <= 0 then begin
|
---|
87 | if OwnsPersistentForm then begin
|
---|
88 | FreeAndNil(PersistentForm);
|
---|
89 | OwnsPersistentForm := False;
|
---|
90 | end;
|
---|
91 | if OwnsThemeManager then begin
|
---|
92 | FreeAndNil(ThemeManager);
|
---|
93 | OwnsThemeManager := False;
|
---|
94 | end;
|
---|
95 | if OwnsTranslator then begin
|
---|
96 | FreeAndNil(Translator);
|
---|
97 | OwnsTranslator := False;
|
---|
98 | end;
|
---|
99 | if OwnsScaleDPI then begin
|
---|
100 | FreeAndNil(ScaleDPI);
|
---|
101 | OwnsScaleDPI := False;
|
---|
102 | end;
|
---|
103 | end;
|
---|
104 | inherited;
|
---|
105 | end;
|
---|
106 |
|
---|
107 | end.
|
---|
108 |
|
---|