PDA

View Full Version : Script Freezes while using forms



Yakman
10-07-2006, 04:58 PM
when i make a form, the script doesnt continue until i close the form.

SafeInitForm
SafeShowForm
writeln('Hello')

i wont get the 'Hello' until i close the form window,

is there a way for the script to carry on even though the form is open, so you can have a form open the whole time the script is running, something like..

frmdesign.stopscript:=true //switch to false


i think this could be useful to show the report in a TEdit or a TMemo as well as the debug log

Rick
10-07-2006, 08:40 PM
Sorry there is no way for the script to execute while it is running.

EDIT: actually if you have a button in your form

below this:
Button1 := TButton.Create(frmDesign);

add this:
Button1.OnClick := @ButtonClick;

then above the InitForm part add:
procedure ButtonClick(sender: TObject);
begin
WriteLn('Hello');
frmDesign.Caption:= frmDesign.Caption + '.';
frmDesign.ModalResult:= mrOk;
end;

that should get the hello to come when you press the button.

try this:

program Yakman;

var
frmDesign : TForm;
Button1 : TButton;

procedure ButtonClick(sender: TObject);
begin
WriteLn('Hello');
frmDesign.Caption:= frmDesign.Caption + '.';
frmDesign.ModalResult:= mrOk;
end;

procedure InitForm;
begin
frmDesign := CreateForm;
frmDesign.Left := 250;
frmDesign.Top := 114;
frmDesign.Width := 263;
frmDesign.Height := 180;
frmDesign.Caption := 'Helper';
frmDesign.Color := clBtnFace;
frmDesign.Font.Color := clWindowText;
frmDesign.Font.Height := -11;
frmDesign.Font.Name := 'MS Sans Serif';
frmDesign.Font.Style := [];
frmDesign.Visible := False;
frmDesign.PixelsPerInch := 96;
Button1 := TButton.Create(frmDesign);
Button1.OnClick := @ButtonClick;
Button1.Parent := frmDesign;
Button1.Left := 79;
Button1.Top := 99;
Button1.Width := 75;
Button1.Height := 25;
Button1.Caption := 'Click Me';
Button1.TabOrder := 1;
end;

procedure SafeInitForm;
var
v: TVariantArray;
begin
setarraylength(V, 0);
ThreadSafeCall('InitForm', v);
end;

procedure ShowFormModal;
begin
frmDesign.ShowModal;
end;

procedure SafeShowFormModal;
var v: TVariantArray;
begin setarraylength(V, 0);
ThreadSafeCall('ShowFormModal', v);
end;

begin
SafeInitForm;
SafeShowFormModal;
end.

or if you want the form to continue running remove the:
frmDesign.Caption:= frmDesign.Caption + '.';
frmDesign.ModalResult:= mrOk;


from:
procedure ButtonClick(sender: TObject);
begin
WriteLn('Hello');
frmDesign.Caption:= frmDesign.Caption + '.';
frmDesign.ModalResult:= mrOk;
end;

hope that helped :)