-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm.Container.pas
116 lines (99 loc) · 2.65 KB
/
Form.Container.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
unit Form.Container;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Form.Encryptor, Form.About, Vcl.Menus,
System.UITypes, Vcl.StdCtrls, Vcl.ExtCtrls;
type
TFormContainer = class(TForm)
MainMenu: TMainMenu;
MenuItemProgram: TMenuItem;
SubMenuItemSettings: TMenuItem;
SubMenuItemExit: TMenuItem;
MenuItemHelp: TMenuItem;
MenuItemAbout: TMenuItem;
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure SubMenuItemExitClick(Sender: TObject);
procedure MenuItemAboutClick(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
function SetForm(AFormClass: TFormClass; AForm: TForm;
AVisible: Boolean): TForm;
procedure CloseActiveForm();
end;
const
RS_EXIT_PROGRAM = 'Are you sure to exit the program?';
var
FormContainer: TFormContainer;
FormEncryptor: TFormEncryptor;
FormAbout: TFormAbout;
ActiveForm: TForm;
implementation
{$R *.dfm}
procedure TFormContainer.FormShow(Sender: TObject);
begin
CloseActiveForm();
ActiveForm := SetForm(TFormEncryptor, FormEncryptor, true);
FormEncryptor := TFormEncryptor(ActiveForm);
end;
procedure TFormContainer.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
CanClose := false;
if MessageDlg(RS_EXIT_PROGRAM, mtConfirmation,
[mbYes, mbNo], 0) = mrYes then
begin
CanClose := true;
end;
end;
procedure TFormContainer.MenuItemAboutClick(Sender: TObject);
begin
FormAbout := TFormAbout.Create(nil);
try
FormAbout.Hide;
FormAbout.ShowModal;
finally
FormAbout.Free;
end;
end;
procedure TFormContainer.SubMenuItemExitClick(Sender: TObject);
begin
Application.MainForm.Close;
end;
// Form based methods
procedure TFormContainer.CloseActiveForm();
begin
if Assigned(ActiveForm) or (ActiveForm <> nil) then
begin
ActiveForm.Close;
FreeAndNil(ActiveForm);
end;
end;
function TFormContainer.SetForm(AFormClass: TFormClass; AForm: TForm;
AVisible: Boolean): TForm;
begin
if not Assigned(AForm) or (AForm = nil) then
begin
AForm := AFormClass.Create(Self);
end;
if AForm.Visible then
begin
if not AVisible then
begin
AForm.Close;
end
else
begin
AForm.BorderStyle := bsNone;
//Width := AForm.Width;
//Height := AForm.Height;
//ClientWidth := AForm.ClientWidth;
//ClientHeight := AForm.ClientHeight;
end;
end;
Result := AForm;
end;
end.