StaticVarSetText, invalid number of arguments


#1

hi,

I get an error 27 call from the DLL saying that I pass an invalid number of argument to StaticVarSetText

In the manual I find it has 3 arguments (https://www.amibroker.com/guide/afl/staticvarsettext.html)

so I programmed:

AmiVar arg3[3];

			arg3[0].type = VAR_STRING;
			arg3[0].string = (char *)gSite.Alloc(100);
			strcpy_s(arg3[0].string, 100, "startx");
			strcat_s(arg3[0].string, 100, cid);
			arg3[1].type = VAR_STRING;	arg3[1].string = dtx.string;
			arg3[2].type = VAR_FLOAT;	arg3[2].val = 0.0f;
			gSite.CallFunction("StaticVarSetText", 3, arg3);

it all seems OK. I thought maybe it gives me the wrong error, but if I comment out

gSite.CallFunction(“StaticVarSetText”, 3, arg3);

I do not get a run-time error. So it seems it does not accept 3 arguments. Anyone see a problem?

cid is a string passed as an argument to the function and dtx is defined as shown below,

thanks, Ed

AmiVar VempOnLButtonIsDown(int NumArgs, AmiVar *ArgsTable)
{
	AmiVar arg1[1], arg2[2], arg3[3], arg4[4], cnt, result;

	char *cid = ArgsTable[0].string;
	float x = ArgsTable[1].val;
	float y = ArgsTable[2].val;

	arg1[0].type = VAR_STRING;
	arg1[0].string = (char *)gSite.Alloc(100);
	strcpy_s(arg1[0].string, 100, "oldx");
	strcat_s(arg1[0].string, 100, cid);
	AmiVar oldx = gSite.CallFunction("StaticVarGetText", 1, arg1);

	arg2[0].type = VAR_FLOAT;	arg2[0].val = x;
	arg2[1].type = VAR_FLOAT;	arg2[1].val = 0.0f;
	AmiVar dtx = gSite.CallFunction("DateTimeToStr", 2, arg2);

#2

Ed, I have not tested your plugin code but the reason seems to be that StaticVarSetText allows four arguments also. But as you mentioned manual does not say so https://www.amibroker.com/guide/afl/staticvarsettext.html

Though the devlog explicitly mentions that only array static vars have compression parameter (so only StaticVarSet is mentioned there)

So yes, StaticVarSet has four arguments since AB 6.07
https://www.amibroker.com/guide/afl/staticvarset.html

But if you do this in StaticVarSetText (adding some number at 4th place -> i.e. “-1” as default )

StaticVarSetText( "varname", "yourtext", 0, -1 );

Then AmiBroker does not complain if adding a 4th argument. It only complains if adding further arguments being more than four ones.

So as for your plugin function just add -1 as a fourth argument for StaticVarSetText.


#3

arghhhh! ok thanks fx, yes I tested using 2 instead of 3. But indeed StaticVarSet has 4 so I should have tested that,

thanks for your help! will test it right now


#4

yes no more errors, now using code similar to:

			arg4[0].type = VAR_STRING;
			arg4[0].string = (char *)gSite.Alloc(100);
			strcpy_s(arg4[0].string, 100, "startx");
			strcat_s(arg4[0].string, 100, cid);
			arg4[1].type = VAR_STRING;
			arg4[1].string = (char *)gSite.Alloc(100);
			strcpy_s(arg4[1].string, 100, dtx.string);
			arg4[2].type = VAR_FLOAT;	arg4[2].val = 0.0f;
			arg4[3].type = VAR_FLOAT;	arg4[3].val = -1.0f;
			gSite.CallFunction("StaticVarSetText", 4, arg4);

thanks again. Part of DLL coding is trial and error programming.


#5

FYI: StaticVarSet and StaticVarSetText are in fact one function. They just differ in signature (i.e. argument type check done by AFL). User’s guide does not mention extra parameter for StaticVarSetText because for strings, there is no time compression and this argument is completely ignored for strings.