From: zzzooo
That's not what I'm trying to do. The function FindBlackChatMessageEx takes a TStringArray for an arg.
Ahh that's why.. That function's signature did not exist on the github so I assumed it was just taking parameters and not an array as a parameter..
Still.. what I said isn't wrong though.. You just have to adjust it to fit your needs. If your parameters are arrays then pass a 2D array. If your parameter is a 2D array, pass a 3D array.
VariantInvoke and ThreadSafeCall both push the indices of the array as arguments to the function onto the stack. When you pass it an array, it thinks that array contains the ARGUMENTS you want to pass.. It will pass each index in that array as an argument.
Ex:
procedure CallMe(arg1, arg2, arg3: Integer);
begin
end;
procedure CallMeMaybe(arg: TIntegerArray);
begin
end;
procedure Where(YouThink: TIntegerArray; Youre: String; Going: Byte; Baby: String);
begin
end;
var
CallMeArgs: TVariantArray;
CallMeMaybeArgs: TVariantArray;
WhereArgs: TVariantArray;
begin
CallMeArgs := [1, 2, 3]; //array containing 3 Arguments for a function that accepts 3 args..
ThreadSafeCall('CallMe', CallMeArgs);
CallMeMaybeArgs := [[1, 2, 3]]; //an array containing a TIntegerArray to be passed to a function that only has one argument..
ThreadSafeCall('CallMeMaybe', CallMeMaybeArgs);
WhereArgs := [[1, 2, 3], 'hello', #32, 'world']; //an array containing a TIntegerArray, a string, a byte and another string..
ThreadSafeCall('Where', WhereArgs);
end.
If your function takes 3 args, you pass ONE array with 3 indices. If you function takes an Array, you pass it an array containing the other array.
Example:
function FindBlackChatMessageEx(text: TStringArray): boolean;
begin
writeln(text);
end;
function CallProc(s: string; params: TVariantArray): Variant;
begin
Result := ThreadSafeCall(s, params);
end;
function WaitFuncEx(Func: string; var Args: TVariantArray; WaitPerLoop, MaxWait: integer): boolean;
var
T: integer;
Temp: variant;
begin
T := GetSystemTime + MaxWait;
while (GetSystemTime < T) do
begin
Temp := CallProc(Func, Args);
Temp := ToStr(Temp);
Result := StrToBoolDef(Temp, False);
if (Result) then
Exit;
Wait(WaitPerLoop);
end;
end;
function WaitChatMessage(args: TVariantArray; time: integer): boolean;
begin
Result := WaitFuncEx('FindBlackChatMessageEx', args, 20 + Random(20), time);
end;
begin
WaitChatMessage([['one', 'two']], 1000);
end.