SDK Arrays

Greetings all again,

I’m creating properties within a new class in my plugin but have come across a problem…how are arrays treated in the SDK so I can access them via Xojo.

For example I have a custom class and I want to have a property which is an array of objects. The following is an example of string of course:

[code]dim Fruits() as FruitData = array(“Apple”, “Orange”, “Banana”, “Pineapple”)

MyClass.MyFruits() = Fruits[/code]

How do I treat the getter and setter functions in the SDK to make this work? Is it a REALobject or REALarray? Can’t seem to work this out. Can’t find an example. Any help appreciated.

Cheers
Grant

Do you mean getter and setter of a “Computed Property”?

It is a REALarray and also a REALobject in the terms of you can retain the Array by calling REALLockObject and REALUnlockObject if you want to store reference to it in your plugin.

The SDK has accessors to get elements from your array. There is also Insert and UBound, but no Delete or Append.

So for your example above where your assigning the Object to your class then you will probably want to call REALLockObject on it to retain it while your class wants to own the reference and then in your destructor you will want to call REALUnlockObject on it.

Thanks for the replies. Here is a snippet of my SDK code:

[code]struct myClassStruct {
REALobject aAlertsData;
};

REALproperty MyClassProps[] = {
{ “”, “AlertsData()”, “AlertINFD2”, REALconsoleSafe, (REALproc)AlertsDataGetter, (REALproc)AlertsDataSetter, },
};[/code]

My plugin won’t load and in fact clobbers other plugins as well if I include the double parenthesis "AlertsData()", but will if I remove them. AlertINFD2 is a custom class defined in my plugin.

Any thoughts?

Cheers
Grant

You can not have a computed property to be an array in Xojo, hence my question above.

Remove the computed property and instead create two methods which act as a getter and a setter. Use the Assigns keyword on the setter so that user in Xojo can use it in an assignment statement instead of a Sub call.

Eli,

It’s not a computed property. It’s a simple single dimensional array.

Cheers
Grant

[quote=291604:@Grant Singleton]Eli,

It’s not a computed property. It’s a simple single dimensional array.

Cheers
Grant[/quote]

All properties registered by the plugins API are computed.

It is as far as I can see it. The docs say:

[quote]REALproperty
This structure is used by a plugin to define a property or a computed property. The difference between the two fundamental types is that a computed property defines a REALproc for the getter and/or setter, while the non-computed property specifies REALstandardGetter and/or REALstandardSetter.

getter: a REALproc for a computed property’s getter, which should be declared as @Type@ GetterName( REALobject, long ). The second parameter is the value specified in the “param” field. Use REALstandardGetter and the “param” field to create a non-computed property (see “param” field for more information).
setter: a REALproc for a computed property’s setter, which should be declared as void SetterName( REALobject, long, @Type@ ). The second parameter is the value specified in the “param” field. Use REALstandardSetter and the “param” field to create a non-computed property (see “param” field for more information).[/quote]
So you need to use REALstandardGetter and REALstandardSetter. As soon as you provide your own getter or setter method, it becomes a computed property.

Eli,

Changed my code to the following, but still the same result.

[code]struct myClassStruct {
REALarray aAlertsData;
};

REALproperty MyClassProps[] = {
{ “”, “AlertsData()”, “AlertINFD2”, REALconsoleSafe, REALstandardGetter, REALstandardSetter, FieldOffset(myClassStruct, aAlertsData) },
};[/code]

When attempting to compile Xojo throws up error:

Can't find a type with this name - ObjectArray

I wouldn’t think this would be so difficult…any ideas?

Cheers
Grant

Maybe you need to clear the Xojo cache.

Like I said, all properties registered by the plugins API are computed. The documentation is wrong and the current behavior dates back at least a decade. A bug report against the documentation would be helpful if you have time.

That they are computed properties in the plugin is clear, but when using REALstandardGetter and REALstandardSetter don’t they become regular properties within Xojo?

Don’t use REALproperty.
Use two methods. I do that in my plugins.

Like this:

Test as Something()
SetTest(values() as Something)
Or
Test(assigns values() as Something)

Nope, still computed properties.

Cleared the cache. Same result. I’ll try Christian’s approach next.

Cheers
Grant

I got it to work, but it’s not the desired result, for example, I can’t do:

MyClass.Alerts.Append new AlertINFD2

Should I just create a new array in my Initializer code in the SDK like so:

me->aAlertsData = REALCreateArray(kTypeObject, -1);

Cheers
Grant

[quote=291627:@Grant Singleton]REALproperty MyClassProps[] = {
{ “”, “AlertsData()”, “AlertINFD2”, REALconsoleSafe, REALstandardGetter, REALstandardSetter, FieldOffset(myClassStruct, aAlertsData) },
};[/quote]

Maybe the bracket () is on wrong thing ? as in should not be on AlertsData but on AlertINFD2.

And of course as they say don’t use REALstandardGetter and REALstandardSetter, And remember when you make the Getters and setters that they also take RBInteger param (if not then your asking for getting crash)

you can’t have () in the name of a property.

Changed to the following…doesn’t work.

REALproperty MyClassProps[] = { { "", "AlertsData", "AlertINFD2()", REALconsoleSafe, REALstandardGetter, REALstandardSetter, FieldOffset(myClassStruct, aAlertsData) }, };

Added my own getter & setter…still doesn’t work.

REALproperty MyClassProps[] = { { "", "AlertsData", "AlertINFD2()", REALconsoleSafe, (REALproc)AlertsDataGetter, (REALproc)AlertsDataSetter }, };

If I remove the parenthesis(), the compiler becomes happy again, but doesn’t recognise the property as an array, which I need it to do so I can access the array elements via the standard dot notation.

Surely someone out there has done this before.

Maybe time to ask Xojo…@Norman Palardy ??

Cheers
Grant

Register two methods instead of a property. One returns the array and the other takes the array as an Assigns parameter.