Jump to content
Wanted

CallProc variable parameters. Is it possible?

Recommended Posts

[sCAR]function WaitFuncEx(Func: string; Parameters: TVariantArray; DesiredResult: Variant; MinWait, MaxWait, MinTotalWait, MaxTotalWait: LongInt): Variant;

var

T: LongInt;

begin

Result := True;

T := GetSystemTime + RandomRange(MinTotalWait, MaxTotalWait);

while (GetSystemTime < T) do

if (CallProc(Func, Parameters) = DesiredResult) then

Exit

else

Wait(RandomRange(MinWait, MaxWait));

Result := False;

end;[/sCAR]

 

works great until you need a parameter that is a var

 

 

For example

 

if you tried to use FindColor the var X, Y would cause a execution error type mismatch. Ignoring it causes a not enough parameters error.

 

Test script

 

[sCAR]function WaitFuncEx(Func: string; Parameters: TVariantArray; DesiredResult: Variant; MinWait, MaxWait, MinTotalWait, MaxTotalWait: LongInt): Variant;

var

T: LongInt;

begin

Result := True;

T := GetSystemTime + RandomRange(MinTotalWait, MaxTotalWait);

while (GetSystemTime < T) do

if (CallProc(Func, Parameters) = DesiredResult) then

Exit

else

Wait(RandomRange(MinWait, MaxWait));

Result := False;

end;

 

var

P: TPoint;

 

begin

FindColor(P.X, P.y, 12312554, 668, 15, 670, 17);

WaitFuncEx('FindColor', [P.X, P.Y, 12312554, 668, 15, 670, 17], True, 100, 250, 90000, 120000);

end.[/sCAR]

 

Execution Error Line 8 invalid typecast

Link to comment
Share on other sites

I found a few errors, though im not sure if thats PS or the compiler itself, but if you comment out line 19 you would get 'Execution Error Line 8 Unknown procedure'.

 

If you try to use CallProc with inbuilt functions/procedures you will get unknown procedure error as above, but if you use CallProc with your own functions/procs it will work but you have to declare the parameters explicitly as TvariantArray.

 

Also CallProc won't return anything(actually it returns nothing) but in simba it returns the correct thing, so think its the compiler's fault?

 

If you don't get what i mean, run this in simba and scar and you'll see:

 

[scar]

program New;

var

v, v1: TVariantArray;

res: variant;

 

procedure Add(n1, n2: Integer);

//procedure Add(var n1: Integer; var n2: Integer); <<<this also works, so the error is not due to the adding var

 

begin

res := n1+n2;

end;

 

function equal(n1, n2: Integer):boolean;

begin

if n1 = n2 then

Result:= True

else

Result:= False;

end;

 

begin

ClearDebug;

v:= [1, 1];

//CallProc('Add', [1, 1]); <<<<<<This wont work

CallProc('Add', v); //<<<<<<but this will

 

writeln(CallProc('equal', v));

end.

[/scar]

 

 

Link to comment
Share on other sites

I don't recall exactly, but I believe it requires trhe variant array to be variable. The function is based directly on methods in the script engine though, so I can't promise it would actually function correctly given PascalScript's legendary high performance and low bugcount. :P

 

Yes it does, but thats not the main problem, CallProc doesn't work for inbuilt functions/procedures(if you get what i mean) and it doesn't return a valid output.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...