SRL Archive - Help and Support

ShowForm Problems


Infantry001

2008-08-18 10:10:59

I'm running a script for SMART (works perfectly, btw :)), and I decided to put in a ChatBox (so I can type while SMART is still enabled). These are the procedures I have used so far:

procedure SmartType(sender : TObject);
var
text : string;
begin
text := TextBox.Text;
if ((text <> '') or (text <> 'Type Here')) then
TypeSend(Text);
TextBox.Text := '';
end;

procedure InitForm;
begin
ChatBox := CreateForm;
with ChatBox do
begin
Left := 356;
Top := 186;
BorderStyle := bsToolWindow;
Caption := 'SMART ChatBox';
ClientHeight := 65;
ClientWidth := 346;
Color := clTeal;
Font.Color := clWindowText;
Font.Height := -11;
Font.Name := 'MS Sans Serif';
Font.Style := [];
PixelsPerInch := 96;
end;
TextBox := TEdit.Create(ChatBox);
with TextBox do
begin
Parent := ChatBox;
Left := 8;
Top := 8;
Width := 329;
Height := 21;
ParentShowHint := False;
ShowHint := False;
TabOrder := 8;
Text := 'Type Here';
end;
TypeButton := TButton.Create(ChatBox);
with TypeButton do
begin
Parent := ChatBox;
Left := 128;
Top := 32;
Width := 75;
Height := 25;
Caption := 'Go!';
OnClick := @SmartType;
TabOrder := 9;
end;
end;

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

procedure ShowInitForm;
begin
ChatBox.Show;
end;

procedure SafeShowInitForm;
var
V : TVariantArray;
begin
SetArrayLength(V, 0);
ThreadSafeCall('ShowInitForm', V);
end;

I call up the form right after I setup my characters and such. However, when I type something in and press the button, both SCAR and SMART crash.

Any possible reasons for this? Was it a mistake on my behalf (I haven't been around for a while, so… yeah), or can SCAR just not handle the multi-tasking?

Sumilion

2008-08-18 11:43:06

Scars form thread is not thread safe, not sure how or why but this means that using the form thread in the scar thread is dangerous. To solve it, use ThreadSafeCall when you call something from the form, in your script. For example :

procedure TypeText;
begin
TypeSend(Edit1.Text);
end;

procedure SafeTypeText;
v: TVariantArray;
begin
ThreadSafeCall('TypeText', v);
end;

and then you call the SafeTypeText procedure ofcourse.

(Edit: Took me a looooong time to figure it out, well, actually Freddy figured it out, but it took a loooong time.)

Infantry001

2008-08-18 11:49:34

Alright, Thanks a bunch!

You'll be sure to see this script out soon ;)

EDIT: Eh.. nvm. Now I'm getting a bunch of runtime errors on perfectly correct code when I click the button (Type Mismatch, Invalid OpCode).

Do you wanna check out the whole script?

Sumilion

2008-08-18 16:36:28

From: Infintry001
Alright, Thanks a bunch!

You'll be sure to see this script out soon ;)

EDIT: Eh.. nvm. Now I'm getting a bunch of runtime errors on perfectly correct code when I click the button (Type Mismatch, Invalid OpCode).

Do you wanna check out the whole script?


Sure