Classes |
Top |
Classes Classes all derive from the root TObject class and follow the classic Delphi syntax. They're reference types, see also Records. Named constructors are supported, as well as class methods, meta-classes, virtual methods, properties and destructors. Properties can optionally be array properties, and can feature an explicit index. Classes can implement Interfaces and they can be partial. You can also declare class methods with "method" as in the Oxygene language, in addition to "procedure" and "function". Additionally classes can be marked as "external", in which case they're meant to expose classes that are not implemented in the script, and unlike interfaces, then can defined fields.
Named constructors are supported, as well as class methods, meta-classes, virtual methods, properties and destructors. Properties can optionally be array properties, and can feature an explicit index. You can also declare class methods with method as in the Oxygene language, in addition to procedure and function. Classic constructor syntax is supported, but you can also specify a default constructor and use the new keyword to instantiate classes. Both lines of code below are equivalent:
obj := TMyObject.Create(parameter);
Visibilities are private, protected, public and published. Private and protected in Smart correspond to strict private and strict protected in Delphi. Classes can implement Interfaces. (See example in the Interfaces section.)
Properties Properties allow to encapsulate with a field-like syntax what can actually be methods (getter/setter). property Name[args : Type] : Type read Getter write Setter; default;
The following form property Name : Type; declares a property backed by a hidden (inaccessible) field. The field can optionally be initialized. The following form property Name; can be used to promote the visibility of a property without altering it in any other way, for instance to make public a property that was previously protected. Properties can also be prefixed by 'class' in which case they will be restricted to class variables, class methods and class properties, but can then be used on the class type (metaclass) and not just on instance.
Default Field Values Class fields can have default values. Types for fields with default values can be type-inferenced.
type
Constructors and Destructors These are supported as normal (a part of TObject). It must be underlined that when writing components (derived from TW3CustomControl, TW3GraphicControl or TW3Component) you rarely override these directly like under Delphi or free pascal, instead you override the protected methods InitializeObject and FinalizeObject. This is to compensate for the lack of BeforeDestruction and AfterConstruction in our object model.
See Partial Classes
See External Classes |