|
|
Data Entry Script
{This script uses Delphi to create the Entry Form itself including fields such as:
• |
Optional text Entry |
• |
Mandatory Text Entry |
• |
Date field with calendar date selection from drop-down calendar |
• |
Field with selection from pre-defined options |
Any entered data can - using scripting - be held against variables and used as required.}
var
frmMain: TForm;
pnlTop: TPanel;
pnlBottom: TPanel;
btnClose: TButton;
btnOK: TButton;
lblField1: TLabel;
lblField2: TLabel;
lblField3: TLabel;
lblField4: TLabel;
edtField1: TEdit;
edtField2: TEdit;
dateField1: TDateTimePicker;
ComboField1: TComboBox;
procedure OKClick;
begin
if (edtfield1.text = '') then
begin
showmessage('Please enter your First Name');
edtfield1.setfocus;
exit;
end;
if (edtfield2.text = '') then
begin
showmessage('Please enter your Last Name');
edtfield2.setfocus;
exit;
end;
if (ComboField1.text = '') then
begin
showmessage('Please select either Male or Female');
ComboField1.setfocus;
exit;
end;
showmessage('Hi ' + edtfield1.text + ', This is a simple Entry Form Example');
end;
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if key = #13 then {The Enter Key}
edtfield2.setfocus;
end;
procedure Edit2KeyPress(Sender: TObject; var Key: Char);
begin
if key = #13 then {The Enter Key}
dateField1.setfocus;
end;
procedure Date1KeyPress(Sender: TObject; var Key: Char);
begin
if key = #13 then {The Enter Key}
ComboField1.setfocus;
end;
procedure CloseClick;
begin
frmMain.close;
end;
begin
frmMain := TForm.Create(nil);
try
frmMain.width := 350;
frmMain.height := 250;
frmMain.caption := 'Ostendo - Data Entry Form';
frmMain.position := poScreenCenter;
frmMain.borderstyle := bsSizeable;
frmMain.name := 'MainForm';
{Top Panel}
pnlTop := TPanel.Create(frmMain);
pnlTop.Parent := frmMain;
pnlTop.Align := alclient;
pnlTop.BevelOuter := bvLowered;
lblfield1 := TLabel.Create(pnlTop);
lblfield1.Parent := pnlTop;
lblfield1.left := 20;
lblfield1.top := 20;
lblfield1.caption := 'First Name';
edtfield1 := TEdit.Create(pnlTop);
edtfield1.Parent := pnlTop;
edtfield1.left := 20;
edtfield1.top := 40;
edtfield1.width := 140;
edtfield1.taborder := 0;
edtfield1.onKeyPress := 'Edit1KeyPress';
lblfield2 := TLabel.Create(pnlTop);
lblfield2.Parent := pnlTop;
lblfield2.left := 180;
lblfield2.top := 20;
lblfield2.caption := 'Last Name';
edtfield2 := TEdit.Create(pnlTop);
edtfield2.Parent := pnlTop;
edtfield2.left := 180;
edtfield2.top := 40;
edtfield2.width := 140;
edtfield2.taborder := 1;
edtfield2.onKeyPress := 'Edit2KeyPress';
lblfield3 := TLabel.Create(pnlTop);
lblfield3.Parent := pnlTop;
lblfield3.left := 20;
lblfield3.top := 80;
lblfield3.caption := 'Birth Date';
dateField1 := TDateTimePicker.Create(pnlTop);
dateField1.Parent := pnlTop;
dateField1.left := 20;
dateField1.top := 100;
dateField1.width := 140;
dateField1.taborder := 2;
dateField1.onKeyPress := 'Date1KeyPress';
lblfield4 := TLabel.Create(pnlTop);
lblfield4.Parent := pnlTop;
lblfield4.left := 180;
lblfield4.top := 80;
lblfield4.caption := 'Male/Female';
ComboField1 := TComboBox.Create(pnlTop);
ComboField1.Parent := pnlTop;
ComboField1.left := 180;
ComboField1.top := 100;
ComboField1.width := 140;
ComboField1.taborder := 3;
ComboField1.Style := csDropDownList;
ComboField1.Items.Add('Female');
ComboField1.Items.Add('Male');
{Create the Bottom Panel with Buttons}
{Bottom Panel}
pnlBottom := TPanel.Create(frmMain);
pnlBottom.Parent := frmMain;
pnlBottom.Height := 50;
pnlBottom.width := 350;
pnlBottom.Align := albottom;
pnlBottom.BevelOuter := bvNone;
{OK Button}
btnOK := TButton.Create(pnlBottom);
btnOK.Parent := pnlBottom;
btnOK.left := 145;
btnOK.Top := 15;
btnOK.Width := 90;
btnOK.Height := 20;
btnOK.Caption := '&OK';
btnOK.OnClick := 'OKClick';
btnOK.Hint := 'Accept Entries';
btnOK.ShowHint := True;
btnOK.taborder := 98;
btnOK.anchors := akright;
{Close Button}
btnClose := TButton.Create(pnlBottom);
btnClose.Parent := pnlBottom;
btnClose.left := 245;
btnClose.Top := 15;
btnClose.Width := 90;
btnClose.Height := 20;
btnClose.Caption := '&Close';
btnClose.OnClick := 'CloseClick';
btnClose.Hint := 'Close Data Entry Screen';
btnClose.ShowHint := True;
btnClose.taborder := 99;
btnClose.anchors := akright;
frmMain.showmodal;
finally
frmMain.free;
end;
end.