Wanted
2007-11-17 17:05:47
Hello, I'm having a problem with using for do loops and arrays to shorten code, this is a very new error, you will find if you run this script in 3.12c or older it will work , however if you run it in the new SCAR 3.12d or 3.12e you will get a Null Pointer Exception error.
the key piece of code being
for some reason it does not like the variable in [here], anyways here's the full script:
Thanks,
-IceFire908
the key piece of code being
for I := 0 to 1 do
begin
Buttons[I] := TButton.Create(frmDesign);
with Buttons[I] do
begin
Parent := frmDesign;
SetBounds(69 + (40 * I), 61 + (40 * I), 75, 25);
Caption := 'Button';
OnClick := @buttonclick;
end;
end;for some reason it does not like the variable in [here], anyways here's the full script:
program New;
var
frmDesign : TForm;
Buttons: array [0..1] of TButton;
procedure buttonclick(sender: TObject);
begin
Writeln('Button pressed!');
frmDesign.Caption:= frmDesign.Caption + '.';
frmDesign.ModalResult:= mrOk;
end;
procedure InitForm;
var
I: Byte;
begin
frmDesign := CreateForm;
frmDesign.Left := 259;
frmDesign.Top := 132;
frmDesign.Width := 354;
frmDesign.Height := 254;
frmDesign.Caption := 'frmDesign';
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;
for I := 0 to 1 do
begin
Buttons[I] := TButton.Create(frmDesign);
with Buttons[I] do
begin
Parent := frmDesign;
SetBounds(69 + (40 * I), 61 + (40 * I), 75, 25);
Caption := 'Button';
OnClick := @buttonclick;
end;
end;
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.I don't know if this is a bug in SCAR or not, maybe someone knows?Thanks,
-IceFire908