In my plugin initializer, I create an array and store it in my ClassData. I was going to lock it but soon realized that
REALLockObject does not function on a
REALArray and that there is no specific lock array method.
How do I lock an array? I should in this case, shouldn’t I?
Also, when a new item is created in my plugin, I return the new item but also place it in the array for access later for various reasons. The new item is created by
REALnewInstance. I lock the new instance before I return it to the caller, should I lock it twice since I am
- adding it to my ClassData array
- returning it to the caller?
you can cast REALarray to REALobject.
REALnewInstance gives +1 reference count. Adding to array adds another reference. So after adding, you need to release the reference.
I’m a bit confused. I’m dealing with two variables here.
- The actual array. I create this in my class
Initializer method using
REALCreateArray. The result of that, I call
REALLockObject on because I am keeping it around, putting it in my
- An item that is created my one of my class methods, say
newObj is created using
REALnewInstance, so it has +1 on the lock. I then add it to the array, so it gets another +1 for a total of +2, correct? That seems correct in my case because I return
newObj to the user. So they have a copy (+1) and I have a copy in the array (+1). I wouldn’t want to unlock in this case, would I?
OK, I really hope this is the last question, but how do you append to the array? I have tried loading the object method:
void (*aAppend)(REALobject, REALobject) = (void (*)(REALobject, REALobject))
REALLoadObjectMethod((REALobject) me->mObjs, "Append(o As Object)");
but that always returns
the SDK has array functions…
Did you try the insert function with right index?
I was under the impression the index had to already exist, otherwise you would get an out of bounds exception? i.e. I created my array with a size of -1 and want to append to the array now.
Huh, that’s weird. I never knew you could do that. For the fun of it, I did:
REALInsertArray(me->mObjs, REALGetArrayUBound(me->mObjs) + 1, obj)
and all worked great. I then tried some Xojo code, and this works too:
[code]Dim a() As String
a.Insert(a.Ubound + 1, “Hello World”)
I never knew that. I was surely expecting an OutOfBounds exception.
Thanks Christian for all your help with this!
Welcome. But before you write all your own plugins, please also check what’s available already.