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 | 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 |
|
---|
33 | procedure Register;
|
---|
34 |
|
---|
35 |
|
---|
36 | implementation
|
---|
37 |
|
---|
38 | procedure Register;
|
---|
39 | begin
|
---|
40 | RegisterNoIcon([TFormEx]);
|
---|
41 | end;
|
---|
42 |
|
---|
43 | { TFormEx }
|
---|
44 |
|
---|
45 | procedure TFormEx.DoShow;
|
---|
46 | begin
|
---|
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 | ThemeManager.UseTheme(Self);
|
---|
53 | end;
|
---|
54 | end;
|
---|
55 |
|
---|
56 | procedure TFormEx.DoCreate;
|
---|
57 | begin
|
---|
58 | if not Assigned(PersistentForm) then begin
|
---|
59 | OwnsPersistentForm := True;
|
---|
60 | PersistentForm := TPersistentForm.Create(nil);
|
---|
61 | end;
|
---|
62 | if not Assigned(ThemeManager) then begin
|
---|
63 | OwnsThemeManager := True;
|
---|
64 | ThemeManager := TThemeManager.Create(nil);
|
---|
65 | end;
|
---|
66 | if not Assigned(Translator) then begin
|
---|
67 | Translator := TTranslator.Create(nil);
|
---|
68 | Translator.POFilesFolder := 'Languages';
|
---|
69 | Translator.Language := Translator.Languages.SearchByCode('');
|
---|
70 | OwnsTranslator := True;
|
---|
71 | end;
|
---|
72 | if not Assigned(ScaleDPI) then begin
|
---|
73 | OwnsScaleDPI := True;
|
---|
74 | ScaleDPI := TScaleDPI.Create(nil);
|
---|
75 | end;
|
---|
76 |
|
---|
77 | Translator.TranslateComponentRecursive(Self);
|
---|
78 | Inc(FCounter);
|
---|
79 | inherited;
|
---|
80 | end;
|
---|
81 |
|
---|
82 | procedure TFormEx.DoClose(var CloseAction: TCloseAction);
|
---|
83 | begin
|
---|
84 | if (not (csDesigning in ComponentState)) then begin
|
---|
85 | PersistentForm.FormFullScreen := FullScreen;
|
---|
86 | PersistentForm.Save(Self);
|
---|
87 | end;
|
---|
88 | inherited;
|
---|
89 | end;
|
---|
90 |
|
---|
91 | procedure TFormEx.DoDestroy;
|
---|
92 | begin
|
---|
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;
|
---|
113 | end;
|
---|
114 |
|
---|
115 | end.
|
---|
116 |
|
---|