PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

New feature: Array of objects

After many requests for this feature, I have decided to implement it.

You can now create arrays of objects and access the object's properties and methods very easily.

Here is a little I used for testing, I have also included a example showing the differences between array of objects and array of structures, they are accessed a little differently.

Code:
#class TObj
Public(a$, b$);

public proc test(z$);
ShowMessage(a$+","+z$);
end;
#endclass

proc main

// Array of Objects
dim(o$, 3);
for (i$, 0, 2);
#object TObj n$;
o$[i$] = &n;$;
end;
for (i$, 0, 2);
o$[i$].a$ = i$+1;
o$[i$].test(i$);
end;

// Array of structures
struct(s$, "a", "b");
tdim(s$, 3);
for (i$, 0, 2);
s.a$[i$] = i$;
end;
for (i$, 0, 2);
ShowMessage(s.a$[i$]);
end;

end;


I hope you guys like it.
I LOOOOOVVVVEEEEE it!
Normally when you access a property of an object it is like this:

Object.property$ = "hello";

however, in the above examples, an array is like this:

Object$[i$].Property$ = 23; //notice all the '$' signs. Shouldn't it be:

Object[i$].property$;

Perhaps you specifically wanted it this way, in which case that is fine, it is just nice to have the format the same for consistancy in the syntax.
Yep it's this way. obj$[i$].property$

PPL get the offset of the variable obj$ at position i$, then get the property$ variable value. It's not conventional but is with PPL anyway! :wink:
thanks
when you free the object array, can you do:

freeobject(ObjectArray$);

or do you have to free each array element?:

freeobject(ObjectArray$[i$]);
No you have to go through the loop.