source: branches/test1/Client/Common/UPersistentForm.pas

Last change on this file was 31, checked in by chronos, 13 years ago
  • Modified: Item list is separated from MainForm as ItemListForm.
  • Modified: Now it is possible to open multiple forms for same operation as View, Edit, Add, List. Open forms are listed in main windows tab list.
File size: 2.7 KB
Line 
1unit UPersistentForm;
2
3{$mode delphi}
4
5interface
6
7uses
8 Classes, SysUtils, Forms, URegistry, LCLIntf, Registry;
9
10type
11
12 { TPersistentForm }
13
14 TPersistentForm = class
15 public
16 RegistryKey: string;
17 RegistryRootKey: HKEY;
18 procedure Load(Form: TForm);
19 procedure Save(Form: TForm);
20 constructor Create;
21 end;
22
23implementation
24
25{ TPersistentForm }
26
27procedure TPersistentForm.Load(Form: TForm);
28var
29 RestoredLeft, RestoredTop, RestoredWidth, RestoredHeight: Integer;
30begin
31 with TRegistryEx.Create do
32 try
33 RootKey := RegistryRootKey;
34 OpenKey(RegistryKey + '\Forms\' + Form.Name, True);
35
36 Form.Width := ReadIntegerWithDefault('Width', Form.Width);
37 Form.Height := ReadIntegerWithDefault('Height', Form.Height);
38 Form.Top := ReadIntegerWithDefault('Top', (Screen.Height - Form.Height) div 2);
39 Form.Left := ReadIntegerWithDefault('Left', (Screen.Width - Form.Width) div 2);
40 if Form.Left < 0 then
41 Form.Left := 0;
42 if Form.Left > (Screen.Width - 50) then
43 Form.Left := Screen.Width - 50;
44 if Form.Top < 0 then
45 Form.Top := 0;
46 if Form.Top > (Screen.Height - 50) then
47 Form.Top := Screen.Height - 50;
48 RestoredWidth := ReadIntegerWithDefault('RestoredWidth', Form.RestoredWidth);
49 RestoredHeight := ReadIntegerWithDefault ('RestoredHeight', Form.RestoredHeight);
50 RestoredTop := ReadIntegerWithDefault ('RestoredTop', (Screen.Height - Form.RestoredHeight) div 2);
51 RestoredLeft := ReadIntegerWithDefault ('RestoredLeft', (Screen.Width - Form.RestoredWidth) div 2);
52 Form.SetRestoredBounds(RestoredLeft, RestoredTop, RestoredWidth, RestoredHeight);
53
54 Form.WindowState := TWindowState(ReadIntegerWithDefault('WindowState', Integer(wsNormal)));
55 if ReadBoolWithDefault('Visible', False) then Form.Show;
56 finally
57 Free;
58 end;
59end;
60
61procedure TPersistentForm.Save(Form: TForm);
62begin
63 with Form, TRegistryEx.Create do
64 try
65 RootKey := RegistryRootKey;
66 OpenKey(RegistryKey + '\Forms\' + Form.Name, True);
67 WriteInteger('Width', Form.Width);
68 WriteInteger('Height', Form.Height);
69 WriteInteger('Top', Form.Top);
70 WriteInteger('Left', Form.Left);
71 WriteInteger('RestoredWidth', Form.RestoredWidth);
72 WriteInteger('RestoredHeight', Form.RestoredHeight);
73 WriteInteger('RestoredTop', Form.RestoredTop);
74 WriteInteger('RestoredLeft', Form.RestoredLeft);
75 WriteInteger('WindowState', Integer(Form.WindowState));
76 WriteBool('Visible', Form.Visible);
77 finally
78 Free;
79 end;
80end;
81
82constructor TPersistentForm.Create;
83begin
84 RegistryRootKey := HKEY_CURRENT_USER;
85end;
86
87end.
88
Note: See TracBrowser for help on using the repository browser.