Ron
2006-12-31 17:27:27
The name is very creative… ReadLn2 :)
Any way, here is the code. With this new ReadLn, you can change the Title,Pretext, and the the question text.
It has to use at least 3 global vars though. Look through the code and you'll see why.
~Ron
Any way, here is the code. With this new ReadLn, you can change the Title,Pretext, and the the question text.
It has to use at least 3 global vars though. Look through the code and you'll see why.
program TestReadLn2;
var
frmReadLn2 : TForm;
ReadLn2Answer: TEdit;
ReadLn2Label1: TLabel;
procedure ReadLn2Cancel(sender: TObject);
begin
ReadLn2Answer.Text := '';
frmReadLn2.MODALRESULT := 2;
end;
procedure ReadLn2CheckEnter(sender: TObject; var key: char);
begin
if (key = Chr(13)) then
begin
frmReadLn2.modalresult := mrOk;
end;
end;
procedure ReadLn2Form;
var
Button1,Button2: TButton;
begin
frmReadLn2 := CreateForm;
with frmReadLn2 do
begin
BorderStyle := bsSingle;
ClientHeight := 90;
ClientWidth := 270;
Position := poScreenCenter;
BorderIcons := [biSystemMenu];
end;
ReadLn2Label1 := TLabel.Create(frmReadLn2);
with ReadLn2Label1 do
begin
Parent := frmReadLn2;
Left := 15;
Top := 12;
Width := 32;
end;
ReadLn2Answer := TEdit.Create(frmReadLn2);
with ReadLn2Answer do
begin
Parent := frmReadLn2;
Left := 15;
Top := 30;
Width := 230;
OnKeyPress := @ReadLn2CheckEnter;
end;
Button1 := TButton.Create(frmReadLn2);
with Button1 do
begin
Parent := frmReadLn2;
Left := 55;
Top := 60;
Caption := 'OK';
ModalResult := 1;
end;
Button2 := TButton.Create(frmReadLn2);
with Button2 do
begin
Parent := frmReadLn2;
Left := 135;
Top := 60;
Caption := 'Cancel';
OnClick := @ReadLn2Cancel;
end;
end;
procedure SafeReadLn2Form;
var
v: TVariantArray;
begin
SetArrayLength(V, 0);
ThreadSafeCall('ReadLn2Form', v);
end;
procedure ShowReadLn2FormModal;
begin
frmReadLn2.ShowModal;
end;
procedure SafeShowReadLn2FormModal;
var
v: TVariantArray;
begin
SetArrayLength(V, 0);
ThreadSafeCall('ShowReadLn2FormModal', v);
end;
function ReadLn2(Question, Title, PreText: string): string;
begin
try
SafeReadLn2Form;
ReadLn2Label1.Caption := Question;
frmReadLn2.Caption := Title;
ReadLn2Answer.Text := PreText;
SafeShowReadLn2FormModal;
Result := ReadLn2Answer.Text;
finally
ReadLn2Answer.Free;
ReadLn2Label1.Free;
FreeForm(frmReadLn2);
except
Result := '';
end;
end;
begin
ClearDebug;
WriteLn(ReadLn2('Do you like this new ReadLn?','ReadLn2 Question','Yes'));
end.
~Ron