class_property

General help with the eC language.
Post Reply
redj
Posts: 105
Joined: Sun Jan 17, 2010 10:03 am

class_property

Post by redj »

Question from JF:
What is the purpose of class_property(...)?

-redj
jerome
Site Admin
Posts: 608
Joined: Sat Jan 16, 2010 11:16 pm

Re: class_property

Post by jerome »

The class_property keyword, a rather 'internally used' feature so far, allows to associate a value (limited to a type that will fit in the size of an 'int' for the moment / an good example of a bad assumption that won't fly on 64 bit ) with that particular class.

It's somewhat analogous to an 'object property', where the property is associated with the instance of a class. Here it is the class itself that has that property. A class property has a set and a get as well. It is defined in a base class like this:

(Inside the Window class)
class_data char * icon;
class_property char * icon
{
set { class_data(icon) = value; }
get { return class_data(icon); }
}

You can them invoke the 'set' from a derived class by putting directly inside your class a statement like:
class Button { ...
class_property(icon) = "<:ecere>controls/button.png";
... }

It is currently most often retrieved using the eClass_GetProperty function (side note: We still need to OO'ify the set of base eC functions, GetProperty should be a method of the 'Class' class).

Note above the usage of 'class_data', which is most often used alongside the class_property.
class_data reserves storage space for a particular piece of data ( that is usually retrieved using class_property ) for all classes derived from this base class.

As said earlier, this class property feature is mostly used internally. In this particular case, to associate an icon with the common control classes. It is also used for specifying the properties of the DisplayDriver s, which is where I assumed you encountered it. Along with the instance-less virtual methods ('static' methods in C++), it forms a framework that resembles Java interfaces.
Post Reply