-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathnewDlg.pas
58 lines (48 loc) · 1.09 KB
/
newDlg.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
unit newDlg;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TNewDialog = class(TForm)
lblName: TLabel;
edtName: TEdit;
btnOK: TButton;
btnCancel: TButton;
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
public
class function ShowNewDialog(const ACaption, AValue: string): string;
end;
var
NewDialog: TNewDialog;
implementation
{$R *.dfm}
{ TNewDialog }
class function TNewDialog.ShowNewDialog(const ACaption, AValue: string): string;
var
dlg: TNewDialog;
begin
Result := '';
dlg := TNewDialog.Create(nil);
try
dlg.Caption := ACaption;
dlg.lblName.Caption := ACaption;
dlg.edtName.Text := AValue;
if (dlg.ShowModal() = mrOK) then
begin
Result := dlg.edtName.Text;
end;
finally
dlg.Free();
end;
end;
procedure TNewDialog.FormCloseQuery(Sender: TObject;
var CanClose: Boolean);
begin
CanClose := (edtName.Text <> '') or (ModalResult = mrCancel);
if not CanClose then
begin
ShowMessage('The value can not be empty');
end;
end;
end.