Foundry
2014-04-30 23:17:14
I have tried putting the TForm a global var and the outcome is the same. I want some type of procedure I can use to display an error or event and a function that can prompt for user input and return a value.
The error log…
{$include_once srlutilities/srlutilities.simba}
//Ignore all of this junk. I wrote it a while ago.
function getBetween(i1, i2: Integer; str: String): String;
var
i, j: Integer;
begin
for i := i1 to i2 do
begin
setLength(result, j + 1);
result[j] := str[i];
inc(j);
end;
end;
//Ignore all of this junk. I wrote it a while ago.
function String.format(CharsPerLine: Integer): TStringArray;
var
i, j, k, Lines: Integer;
Markers: TIntegerArray;
begin
setLength(Markers, 1);
for i := 1 to length(self) do
begin
if (self[i] = #32) or (i = length(self)) then
Markers[j] := i;
if i - (CharsPerLine * Lines) = CharsPerLine then
begin
inc(j);
inc(Lines);
setLength(Markers, j + 1);
end;
end;
j := 0;
k := 1;
for i := 0 to high(Markers) do
begin
setLength(result, j + 1);
result[j] := getBetween(k - 1, Markers[i], self);
inc(j);
k := Markers[i];
end;
if length(result) > 1 then
for i := 1 to high(result) do
begin
//delete the space in the beginning...
end;
end;
// This is what I am trying to fix.
procedure showError(ErrorMessage: String; Width: Integer = 200{how long in pixels it is});
var
mainErrorForm: TForm;
btnOkay: TButton;
lblErrorMessage: TLabel;
Lines: TStringArray;
begin
Lines := ErrorMessage.format(Width - 20);
mainErrorForm.init(nil);
with mainErrorForm do
begin
setWidth(Width + 30);
setHeight(50 + (length(Lines) * 13));
setCaption('Error!');
setPosition(poScreenCenter);
end;
btnOkay.init(mainErrorForm);
with btnOkay do
begin
setWidth(40);
setHeight(15);
setCaption('Okay');
setTop(mainErrorForm.getTop() + mainErrorForm.getHeight() - 20);
setLeft(mainErrorForm.getLeft() + mainErrorForm.getWidth() - 45);
setOnClick(mainErrorForm.free);
end;
mainErrorForm.showModal();
sync(mainErrorForm);
end;
function promptInt(Title: String): Integer;
var
mainform: TForm;
btnOkay: TButton;
edtIntField: TEdit;
lblTitle: TLabel;
debugbox: TMemo;
begin
end;
begin
showError('why isn't this working');
end;
The error log…
Program exception!
Stacktrace:
Exception class: EThread
Message: CheckSynchronize called from non-main thread "$2E5C"
$00459701
$005094BD
$0041F5A3
$0080D4FF
$0073D402
$005FBBCB
$00459118
Simba Version: 1004