PocketMatrix forums

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

additional Properties?

Is there a way to create an object with nested properties? Many Controls are able to do this.

Example:

Item.Car.Color$ = "red";

where you create an item, then depending on the item, there are individual properties for this?

Textbox controls use this a lot.
Unfortunately not now. It is something I had in my things-to-do for a little while. Basically it will be called struct inside struct.

Something like this:

Code:
struct(s1$, "Color", "Size");
struct(s2$, "Name", "X", "Y", "Props", s1$);


Then you will be able to do this:

Code:
s2.Name$ = "MyControl";
s2.Props.Color$ = 0xFFFFFFFF;
s2.Props.Size$ = 10;


I will move it up my priority list then.
this would actually solve a sticky parts in coding. I am glad you had already thought this through.
By looking at my code, it might be easier to do than I thought. I will work on it tomorrow and give you an update then.
Struct within struct syntax is now implemented. You can do the following with any restrictions:

Code:
struct(s1$, "a", "b");
struct(s2$, "c", s1$, "d");
struct(s3$, "e", "f", s2$);

s3.f.c.a$ = 10;
s3.f.c.b$ = 20;
ShowMessage(s3.f.c.a$ + s3.f.c.b$);

list(l$);
for (i$, 1, 10)
add(l$);
struct(l$, "e", "f", s2$);
l.f.c.a$ = i$;
end;

foreach (l$)
ShowMessage(l.f.c.a$);
end;


I hope you enjoy! :)
Nice! is this only for structs, right? can you do nested properties with Objects?
Yep, through Object inheritance.
SO by creating another class that inherits the mother clas, you can have class.subclass.color?
Actually no. You can do this:

Code:
#class Class1
public (a$, b$);
#endclass

#class Class1 Class2
public (d$, e$);
#endclass

proc main
#object Class2 o$;
o.a$ = 10; // a$ & b$ are inherited from Class1
end;


This is object inheritance.

If you want a structure inside an object, you will have to do this:

Code:
#class MyClass
struct(s$, "a", "b");
Public(s$);
#endclass

proc main
#object MyClass o$;
o.s.a$ = 10;
end;


I think that more what you are looking for.
right.