1 | unit FormEx;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, Forms, PersistentForm, Theme, Translator;
|
---|
7 |
|
---|
8 | type
|
---|
9 |
|
---|
10 | { TFormEx }
|
---|
11 |
|
---|
12 | TFormEx = class(TForm)
|
---|
13 | private
|
---|
14 | FCounter: Integer; static;
|
---|
15 | public
|
---|
16 | PersistentForm: TPersistentForm; static;
|
---|
17 | ThemeManager: TThemeManager; static;
|
---|
18 | Translator: TTranslator; static;
|
---|
19 | procedure DoShow; override;
|
---|
20 | procedure DoCreate; override;
|
---|
21 | procedure DoClose(var CloseAction: TCloseAction); override;
|
---|
22 | procedure DoDestroy; override;
|
---|
23 | end;
|
---|
24 |
|
---|
25 | procedure Register;
|
---|
26 |
|
---|
27 |
|
---|
28 | implementation
|
---|
29 |
|
---|
30 | procedure Register;
|
---|
31 | begin
|
---|
32 | RegisterNoIcon([TFormEx]);
|
---|
33 | end;
|
---|
34 |
|
---|
35 | { TFormEx }
|
---|
36 |
|
---|
37 | procedure TFormEx.DoShow;
|
---|
38 | begin
|
---|
39 | inherited;
|
---|
40 | PersistentForm.Load(Self);
|
---|
41 | end;
|
---|
42 |
|
---|
43 | procedure TFormEx.DoCreate;
|
---|
44 | begin
|
---|
45 | if not Assigned(PersistentForm) then
|
---|
46 | PersistentForm := TPersistentForm.Create(nil);
|
---|
47 | if not Assigned(ThemeManager) then
|
---|
48 | ThemeManager := TThemeManager.Create(nil);
|
---|
49 | if not Assigned(Translator) then begin
|
---|
50 | Translator := TTranslator.Create(nil);
|
---|
51 | Translator.POFilesFolder := 'Languages';
|
---|
52 | Translator.Language := Translator.Languages.SearchByCode('');
|
---|
53 | end;
|
---|
54 | Translator.TranslateComponentRecursive(Self);
|
---|
55 | ThemeManager.UseTheme(Self);
|
---|
56 | Inc(FCounter);
|
---|
57 | inherited;
|
---|
58 | end;
|
---|
59 |
|
---|
60 | procedure TFormEx.DoClose(var CloseAction: TCloseAction);
|
---|
61 | begin
|
---|
62 | PersistentForm.Save(Self);
|
---|
63 | inherited;
|
---|
64 | end;
|
---|
65 |
|
---|
66 | procedure TFormEx.DoDestroy;
|
---|
67 | begin
|
---|
68 | Dec(FCounter);
|
---|
69 | if FCounter <= 0 then begin
|
---|
70 | FreeAndNil(PersistentForm);
|
---|
71 | FreeAndNil(ThemeManager);
|
---|
72 | FreeAndNil(Translator);
|
---|
73 | end;
|
---|
74 | inherited;
|
---|
75 | end;
|
---|
76 |
|
---|
77 | end.
|
---|
78 |
|
---|