-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathname.pas
71 lines (52 loc) · 1.21 KB
/
name.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
unit Name;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
ExtCtrls, MaskEdit;
type
{ TNameForm }
TNameForm = class(TForm)
CancelButton: TButton;
OKButton: TButton;
NameEdit: TEdit;
Label1: TLabel;
Panel1: TPanel;
procedure CancelButtonClick(Sender: TObject);
procedure OKButtonClick(Sender: TObject);
procedure NameEditKeyPress(Sender: TObject; var Key: char);
private
public
end;
var
NameForm: TNameForm;
implementation
{$R *.lfm}
{ TNameForm }
procedure TNameForm.OKButtonClick(Sender: TObject);
//close the Name form
begin
NameForm.ModalResult:=mrOK;
end;
procedure TNameForm.CancelButtonClick(Sender: TObject);
//close the Name form
begin
NameForm.ModalResult:=mrCancel;
end;
procedure TNameForm.NameEditKeyPress(Sender: TObject; var Key: char);
//restrict allowed key codes
begin
//accept input
if Key=#13 then
OKButtonClick(nil);
//decline input
if Key=#27 then
begin
NameEdit.Text:='';
CancelButtonClick(nil);
end;
//allow only basic ASCII and some CTRL+[C/V/X/Z] control codes
if not (Key in [#3, #8, #22, #24, #26, #31..#127]) then
Key:=#0;
end;
end.