-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathNewFormUnit.pas
118 lines (105 loc) · 2.42 KB
/
NewFormUnit.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
117
118
unit NewFormUnit;
{$MODE Delphi}
interface
uses
SysUtils, Forms, Dialogs, StdCtrls;
type
TNewForm = class(TForm)
Button1: TButton;
WidthEdit: TEdit;
HeightEdit: TEdit;
Width: TLabel;
Height: TLabel;
VGA: TRadioButton;
SVGA: TRadioButton;
XGA: TRadioButton;
Custom: TRadioButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
_confirm: Boolean;
public
{ Public declarations }
function getWidth(): Integer;
function getHeight(): Integer;
end;
var
NewForm: TNewForm;
implementation
{$R *.lfm}
function TNewForm.getWidth(): Integer;
var
i: Integer;
begin
Result := 0;
if not _confirm then
Exit;
if VGA.Checked then Result := 640;
if SVGA.Checked then Result := 800;
if XGA.Checked then Result := 1024;
if Custom.Checked then
begin
for i := 1 to Length(WidthEdit.Text) do
if not (WidthEdit.Text[i] in ['0'..'9']) then
begin
Result := 0;
Exit;
end;
Result := StrToInt(WidthEdit.Text);
end;
end;
function TNewForm.getHeight(): Integer;
var
i: Integer;
begin
Result := 0;
if not _confirm then
Exit;
if VGA.Checked then Result := 480;
if SVGA.Checked then Result := 600;
if XGA.Checked then Result := 768;
if Custom.Checked then
begin
for i := 1 to Length(HeightEdit.Text) do
if not (WidthEdit.Text[i] in ['0'..'9']) then
begin
Result := 0;
Exit;
end;
Result := StrToInt(HeightEdit.Text);
end;
end;
procedure TNewForm.FormCreate(Sender: TObject);
begin
_confirm := false;
end;
procedure TNewForm.Button1Click(Sender: TObject);
var
i: Integer;
begin
_confirm := true;
if not Custom.Checked then
begin
Close();
Exit;
end;
for i := 1 to Length(WidthEdit.Text) do
if not (WidthEdit.Text[i] in ['0'..'9']) then
_confirm := false;
for i := 1 to Length(HeightEdit.Text) do
if not (HeightEdit.Text[i] in ['0'..'9']) then
_confirm := false;
if (Length(WidthEdit.Text) = 1) and (WidthEdit.Text[1] = '0') then _confirm := false;
if (Length(HeightEdit.Text) = 1) and (HeightEdit.Text[1] = '0') then _confirm := false;
if _confirm then
Close()
else
MessageDlg('Width and height must be positive integers!', mtError, [mbOK], 0);
end;
procedure TNewForm.FormShow(Sender: TObject);
begin
_confirm := false;
end;
end.