How plugin can get TYPE of Array items?

Hi guys,

in plugin SDK exists

typedef enum REALArrayType {
kTypeSInt32 = 0, // 32-bit integer, or color

It is used only by
REALarray REALCreateArray(REALArrayType type, RBInteger bounds) RB_WARN_UNUSED_RESULT;

i.e. when PLUGIN create array to send to Xojo.

What about reverse? In Xojo user can create arrays with different items:
params_s() as string
params_v() as variant

   foo( params_s )
   foo( params_v )

in Plugin we can make
foo( REALarray params )

But to be able correctly handle both these cases, we need be able ask TYPE of item of array.
And I do not see how todo this?

[quote=223962:@Ruslan Zasukhin]But to be able correctly handle both these cases, we need be able ask TYPE of item of array.
And I do not see how todo this?[/quote]

The declaration in your REALMethodDefinition specifies which kind of array things are. The compiler will prevent the user from passing the wrong kind of array, so your code knows what to deal with.

Well, I afraid this not works with new SDK from 2015r3. Let me show why.

We have methods

{ 	(REALproc) Database_SqlExecute_2,
	REALnoImplementation,
	"SqlExecute(inQuery as string, inBinds() as String ) as integer", REALconsoleSafe },

{ 	(REALproc) Database_SqlExecute_3,
	REALnoImplementation,
	"SqlExecute(inQuery as string, inBinds() as Variant ) as integer", REALconsoleSafe },

For years we did have corresponded methods

int Database_SqlExecute_2( REALobject instance, REALstring inQuery, REALstringArray inBinds )
int Database_SqlExecute_3( REALobject instance, REALstring inQuery, REALobjectArray inBinds )

But now, REALstringArray and REALobjectArray are deprecated and, even worse they are typedef to REALobject.

typedef REALobject REALstringArray;
typedef REALobject REALobjectArray;

So our methods have the same third parameter…
I have try to comment one of them, and use REALarray instead of REALobjectArray.

But this bring me to question – how to differ TYPES of Arrays.

I afraid, that new SDK in fact break our code.

The only solution I see so far, is to have as the main method
SqlExecute(inQuery as string, inBinds() as Variant ) as integer

And rename the second, for example as following:
SqlExecuteWithStrings(inQuery as string, inBinds() as String ) as integer

But this is workaround from our side.

The best solution could be If REAL plugin SDK give me something as
void REALGetArrayValueType(REALarray arr, RBInteger index, REALArrayType* outType );

or just from array itself
void REALGetArrayType(REALarray arr, REALArrayType* outType );

Ruslan, there is no problem.

you declare xojo parameters and bind to a C function.
So bind “values() as string” to one function and “value() as variant” to other.
Like you used to do before.
Just that the C functions have different names.

you could also use Variant functions to ask for the type of variant and provide array. That should give the right value.

[quote=223973:@Ruslan Zasukhin]Well, I afraid this not works with new SDK from 2015r3. Let me show why.

We have methods

{ 	(REALproc) Database_SqlExecute_2,
	REALnoImplementation,
	"SqlExecute(inQuery as string, inBinds() as String ) as integer", REALconsoleSafe },

{ 	(REALproc) Database_SqlExecute_3,
	REALnoImplementation,
	"SqlExecute(inQuery as string, inBinds() as Variant ) as integer", REALconsoleSafe },

For years we did have corresponded methods

int Database_SqlExecute_2( REALobject instance, REALstring inQuery, REALstringArray inBinds )
int Database_SqlExecute_3( REALobject instance, REALstring inQuery, REALobjectArray inBinds )

But now, REALstringArray and REALobjectArray are deprecated and, even worse they are typedef to REALobject.

typedef REALobject REALstringArray;
typedef REALobject REALobjectArray;

So our methods have the same third parameter…
I have try to comment one of them, and use REALarray instead of REALobjectArray.

But this bring me to question – how to differ TYPES of Arrays.[/quote]

You already have two different functions to handle different array types. In Database_SqlExecute_2 you already know that you’re dealing with a string array because that’s what the REALMethodDefinition says.

If you want to get rid of the deprecation warnings, you can just switch the parameters to be REALarray and use REALGetArrayValueString in Database_SqlExecute_2 and REALGetArrayValueObject in Database_SqlExecute_3.

by the way for my own plugins I have explicit array types myself.
So I don’t use the “typedef REALobject REALstringArray;” for my plugins.
I prefer to have struct types here so compiler can report errors.

Thank you Christian,

you have set me on the right track.

Trouble was from helper-sub-functions. I have set them different names now to differ with REALarray.
All right now :slight_smile: