SRL Archive - General Botting Help

form function help


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.

{$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

Olly

2014-05-01 00:04:59

You should really just use a MessageDlg, or a ShowMessage, but you aren't calling sync correctly you need to sync the procedure that shows the form.

ps:
GetBetween() is pretty much copy(s, e: integer, s: string);

Brandon

2014-05-01 03:04:38


var
UserInput: String;
begin
if (InputQuery('Caption', 'Message', UserInput)) then
begin
writeln(UserInput);
end;
end.


Why bother synchronising if the form is modal and on the same thread as the calling func?

Foundry

2014-05-01 08:12:55

From: Olly
You should really just use a MessageDlg, or a ShowMessage, but you aren't calling sync correctly you need to sync the procedure that shows the form.

ps:
GetBetween() is pretty much copy(s, e: integer, s: string);


Oh ok. I was just trying to adapt what I saw in the SRL payer manager… have no idea how it works. Also, I know that Simba has string functions I could have used but I didn't know that at the time.
@Brandon; Thanks, thought there might be a simple solution.

masterBB

2014-05-01 10:43:28

From: Brandon
Why bother synchronising if the form is modal and on the same thread as the calling func?


Expanding on this:
Synchronising is done when you use multiple threads. When you use showModal the script thread just waits till the form is closed and continues below. So there is nothing to sync.

threading and common problems in a nutshell:

Imagine you live in a house alone. You can do anything. Going to the bathroom with your eyes closed while walking through you hallways naked is no problem at all. The problem starts when there are two people living in a house.

When you go into the bathroom to do some serious bussiness you might find the other person doing the same thing at the same time. This is a big problem.[citation needed] To solve this adding a lock to the bathroom door seems like a good idea. This is called syncing. The only downside is that you have to wait till the other person is ready…

Brandon

2014-05-01 13:25:50

From: masterBB
Expanding on this:
Synchronising is done when you use multiple threads. When you use showModal the script thread just waits till the form is closed and continues below. So there is nothing to sync.

threading and common problems in a nutshell:

Imagine you live in a house alone. You can do anything. Going to the bathroom with your eyes closed while walking through you hallways naked is no problem at all. The problem starts when there are two people living in a house.

When you go into the bathroom to do some serious bussiness you might find the other person doing the same thing at the same time. This is a big problem.[citation needed] To solve this adding a lock to the bathroom door seems like a good idea. This is called syncing. The only downside is that you have to wait till the other person is ready…



Good explanation but I'm a bit pedantic about the lock part. Isn't that just "locking" and as a result of locking operations become synchronous? For example, you can have lock-free queues and they can still be in sync and thread-safe with low latency operations.

Another thing is that if it is read-only operations, no locking or syncing would be needed since no modifications are done.. I think your explanation is "how" to make operations synchronous.


However in the case of Simba forms, I think you actually have the BEST analogy I have ever seen. +5 from me.

Foundry

2014-05-03 23:12:12

Is there a function that prompts a drop down box or does that require me making a form?

masterBB

2014-05-04 08:51:22

From: Brandon
Good explanation but I'm a bit pedantic about the lock part. Isn't that just "locking" and as a result of locking operations become synchronous? For example, you can have lock-free queues and they can still be in sync and thread-safe with low latency operations.

Another thing is that if it is read-only operations, no locking or syncing would be needed since no modifications are done.. I think your explanation is "how" to make operations synchronous.


However in the case of Simba forms, I think you actually have the BEST analogy I have ever seen. +5 from me.


Tbh, I have only used openMP with that pragma shit before. I never really had a need for multithreading yet. I only made some hello world like apps with syncing for educational purposes. So you're probably right on the locking thing ;)

From: Foundry
Is there a function that prompts a drop down box or does that require me making a form?


You have to create it

tiffanygraff

2014-06-03 03:06:41

Nice thread you have to share here,, thanks