-
Notifications
You must be signed in to change notification settings - Fork 2
/
FormAdd.pas
117 lines (95 loc) · 2.63 KB
/
FormAdd.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
unit FormAdd;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ComCtrls,
System.RegularExpressions, DateUtils, Types, TOperativeUnit, Vcl.ExtDlgs;
procedure Append(item : TElemType); stdcall
external 'LinkedList.dll' name 'Append';
type
TForm1 = class(TForm)
edtFirstName: TEdit;
Label1: TLabel;
edtLastName: TEdit;
edtNickName: TEdit;
edtPlaceOfBirth: TEdit;
dtpBirthDate: TDateTimePicker;
Nazwisko: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
btnAdd: TButton;
btnClose: TButton;
epFirstName: TLabel;
epLastName: TLabel;
epNickName: TLabel;
epDateOfBirth: TLabel;
epPlaceOfBirth: TLabel;
procedure btnAddClick(Sender: TObject);
procedure btnCloseClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
function ValidateForm : Boolean;
public
HasAdded : Bool;
end;
var
Form1: TForm1;
implementation
function TForm1.ValidateForm: Boolean;
var
isValid, tmp : Boolean;
namePattern : string;
regex : TRegEx;
begin
isValid := True;
namePattern := '^[a-zA-z\-\ Œ£ê󳜹¿Ÿæñ]+$';
regex.Create(namePattern);
tmp := regex.IsMatch(edtFirstName.Text);
epFirstName.Visible := not tmp;
isValid := isValid and tmp;
tmp := regex.IsMatch(edtLastName.Text);
epLastName.Visible := not tmp;
isValid := isValid and tmp;
tmp := regex.IsMatch(edtNickName.Text);
epNickName.Visible := not tmp;
isValid := isValid and tmp;
tmp := regex.IsMatch(edtPlaceOfBirth.Text);
epPlaceOfBirth.Visible := not tmp;
isValid := isValid and tmp;
tmp := (CompareDate( dtpBirthDate.Date, Now) <> GreaterThanValue);
epDateOfBirth.Visible := not tmp;
isValid := isValid and tmp;
Result := isValid;
end;
{$R *.dfm}
procedure TForm1.btnAddClick(Sender: TObject);
var
entry : TOperative;
begin
if ValidateForm then
begin
//TODO dodaj co trzeba
entry.FirstName := edtFirstName.Text;
entry.LastName := edtLastName.Text;
entry.NickName := edtNickName.Text;
entry.BirthPlace := edtPlaceOfBirth.Text;
entry.DateOfBirth := dtpBirthDate.DateTime;
Append(entry);
edtFirstName.Text := '';
edtLastName.Text := '';
edtNickName.Text := '';
edtPlaceOfBirth.Text := '';
edtFirstName.SetFocus;
HasAdded := true;
end;
end;
procedure TForm1.btnCloseClick(Sender: TObject);
begin
Close;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
HasAdded := False;
end;
end.