Huh?
1) I told you in both posts exactly, what is wrong.
2) A "basic" example is in the autodoc for application.library/prefsobjects, node -prefsobjects-. You are asking questions specific to your use-case.
3a) With regard to your first question "multiple sub-items in an array": In order to understand PrefsObjects, you need a basic knowledge about XML, which is beyond the scope of our documentation, because it is an industry standard. There are plenty of sources for that out there in the web. In your example, Tab0 and Tab1 would obviously need to be arrays as well to be able to hold multiple sub-items.
3b) The error in the code of your second post is what I described: you are overwriting WindowObj in any iteration of the loop with a new array pointer containing exactly ONE number, because you don't tell PrefsArray() to which array it is supposed to add the newly created number objects. Admittedly the autodocs for PrefsObjects aren't the best we have, but this is clearly described in them. So your loop would have to look like this:
Code: Select all
...
/* Warning: this code does no error checking */
/* Create the the initially empty array object */
PrefsObject *WindowObj = IPrefsObjects->PrefsArray(NULL, NULL, ALPO_Alloc, 0, TAG_DONE);
for (x = 0; x < NumItems; x++)
{
/* Access the old WindowObj array (created above for 1st iteration, returned by the loop's PrefsArray()
* for any following iteration), add a newly created number object to it and save the returned array object
* for the next iteration, which might or might not be the same as before.
* That way we are telling PrefsArray() to which array it has to add the newly created numbers.
*/
WindowObj = IPrefsObjects->PrefsArray(WindowObj, NULL,
ALPOARR_AddObj,
IPrefsObjects->PrefsNumber(NULL, NULL,
ALPONUM_AllocSetLong, myArray[x],
TAG_DONE),
TAG_DONE);
}
IPrefsObjects->DictSetObjectForKey(myPrefsDict, WindowObj, "MyArray");