How to Use AMachine.SetInputArg()

Hi.

I am using C++ Builder and scripting in Basic.

I have a
function in C++ I wanted to put a wrapper around. To improve
performance, I wanted to use the SetInPutArg rather than 
ReturnOutputArg.

My C++ function wrapper is such:

UnicodeString String = AMachine->GetInputArgAsString(0);
UnicodeString Name1, Name2;

ParseString(String, &Name1, &Name2);

AMachine->SetInputArg(1, Name1);
AMachine->SetInputArg(2, Name2);
My Basic Script:
Name1 = ""
Name2 = ""

VBParseString(StringToParse, Name1, Name2)
Now I get an exception:
EatScripterRuntime with message 'RUNTIME ERROR method expects argument 1 as variable reference'
Now
I have tried AMachine->SetInputArg(1, &Name1); but that gives
the same error. But i also may not be declaring it as ByRef in the basic
script correctly? Any help would be appreciated. Thanks.

Hi,

 When registering the function using DefineMethod, you must call SetVarArgs([1, 2]) in the created method to specify what parameters will be passed as reference:

DefineMethod('VBParseString', {...}).SetVarArgs([1, 2]);

Wagner,

Whenever I use .SetVarArgs, I get an Expression syntax error. Looking at the atScript.hpp, it shows:

SetVarArgs(System:: Byte *argi, const int argi_High)

So I think I might need an additional argument than just the array [1,2].

is argi_High similar to needing me to pass in a size for the array?

Ok, I gave you an example in Delphi. You just need to use the C++ syntax to pass an "array of byte" to the function, which in C++ should be something like this:


SetVarArgs(OPENARRAY(System::Byte, ((1, 2)));

Ok. It is working now thanks to your help. Here is how I had to adjust my C++:

TatMethod *ParseStringMethod = Scripter1->DefineMethod(...);
System::Byte *Bytes = new System::Byte[2];
Bytes[0] = 1;
Bytes[1] = 2;
ParseStringMethod->SetVarArgs(Bytes, 2);

I couldn't remember the shorthand for making the Bytes array. Thanks and hopefully this helps others as well.