source: trunk/Forms/UFormMain.pas

Last change on this file was 28, checked in by chronos, 20 months ago
  • Modified: Do not create all application forms at initialization phase but dynamically.
File size: 2.6 KB
Line 
1unit UFormMain;
2
3interface
4
5uses
6 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Menus,
7 ComCtrls, UFormTables;
8
9type
10
11 { TFormMain }
12
13 TFormMain = class(TForm)
14 CoolBar1: TCoolBar;
15 MainMenu1: TMainMenu;
16 MenuItem1: TMenuItem;
17 MenuItem2: TMenuItem;
18 MenuItem3: TMenuItem;
19 MenuItem4: TMenuItem;
20 MenuItem5: TMenuItem;
21 MenuItem6: TMenuItem;
22 MenuItem7: TMenuItem;
23 MenuItem8: TMenuItem;
24 MenuItemPreferences: TMenuItem;
25 StatusBar1: TStatusBar;
26 ToolBar1: TToolBar;
27 ToolButton1: TToolButton;
28 ToolButton2: TToolButton;
29 ToolButton3: TToolButton;
30 procedure FormActivate(Sender: TObject);
31 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
32 procedure FormCreate(Sender: TObject);
33 procedure FormDestroy(Sender: TObject);
34 procedure FormShow(Sender: TObject);
35 private
36 procedure SetToolbarHints;
37 public
38 FormTables: TFormTables;
39 procedure DockInit;
40 procedure UpdateInterface;
41 end;
42
43var
44 FormMain: TFormMain;
45
46
47implementation
48
49{$R *.lfm}
50
51uses
52 UCore;
53
54{ TFormMain }
55
56procedure TFormMain.FormActivate(Sender: TObject);
57begin
58 Core.Init;
59 // TODO: Toolbar height is incorrectly calculated
60 ToolBar1.ButtonHeight := ToolBar1.Height;
61end;
62
63procedure TFormMain.FormClose(Sender: TObject; var CloseAction: TCloseAction);
64begin
65 Core.Done;
66 Core.PersistentForm1.Save(Self);
67end;
68
69procedure TFormMain.FormCreate(Sender: TObject);
70begin
71 FormTables := TFormTables.Create(nil);
72end;
73
74procedure TFormMain.FormDestroy(Sender: TObject);
75begin
76 FreeAndNil(FormTables);
77end;
78
79procedure TFormMain.FormShow(Sender: TObject);
80begin
81 Core.PersistentForm1.Load(Self, True);
82 SetToolbarHints;
83 DockInit;
84end;
85
86procedure TFormMain.DockInit;
87begin
88 FormTables.ManualDock(FormMain, nil, alClient);
89 FormTables.Align := alClient;
90 FormTables.Show;
91end;
92
93procedure TFormMain.UpdateInterface;
94var
95 NewCaption: string;
96begin
97 NewCaption := Application.Title;
98 if Assigned(Core.DbClient) then
99 NewCaption := Core.DbClient.ConnectProfile.Name + ' - ' + NewCaption;
100 FormMain.Caption := NewCaption;
101 FormTables.UpdateInterface;
102end;
103
104procedure TFormMain.SetToolbarHints;
105var
106 I: Integer;
107 J: Integer;
108 Control: TControl;
109begin
110 for J := 0 to CoolBar1.ControlCount - 1 do begin
111 Control := CoolBar1.Controls[J];
112 if Control is TToolBar then begin
113 for I := 0 to TToolBar(Control).ButtonCount - 1 do begin
114 TToolBar(Control).Buttons[I].ShowHint := True;
115 TToolBar(Control).Buttons[I].Hint := TToolBar(Control).Buttons[I].Caption;
116 end;
117 end;
118 end;
119end;
120
121end.
122
Note: See TracBrowser for help on using the repository browser.