source: branches/xpascal/Packages/Common/FormEx.pas

Last change on this file was 228, checked in by chronos, 17 months ago
  • Modified: Use TFormEx for all forms.
  • Modified: Test forms moved into Common package.
File size: 1.5 KB
Line 
1unit FormEx;
2
3interface
4
5uses
6 Classes, SysUtils, Forms, PersistentForm, Theme, Translator;
7
8type
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
25procedure Register;
26
27
28implementation
29
30procedure Register;
31begin
32 RegisterNoIcon([TFormEx]);
33end;
34
35{ TFormEx }
36
37procedure TFormEx.DoShow;
38begin
39 inherited;
40 PersistentForm.Load(Self);
41end;
42
43procedure TFormEx.DoCreate;
44begin
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;
58end;
59
60procedure TFormEx.DoClose(var CloseAction: TCloseAction);
61begin
62 PersistentForm.Save(Self);
63 inherited;
64end;
65
66procedure TFormEx.DoDestroy;
67begin
68 Dec(FCounter);
69 if FCounter <= 0 then begin
70 FreeAndNil(PersistentForm);
71 FreeAndNil(ThemeManager);
72 FreeAndNil(Translator);
73 end;
74 inherited;
75end;
76
77end.
78
Note: See TracBrowser for help on using the repository browser.