Anonymous classes

Top  Previous  Next

Anonymous classes

In traditional Object Pascal all classes inherit from a root type called TObject. Anonymous classes meant that Smart Pascal is able to directly import and make use of external classes. This allows the user to simply define a class as external, and classes written in JavaScript which match the interface can thus be created and used along-side those written in pascal. This is achieved by allowing objects to be rooted from nothing (i.e: no pre-defined constructor logic and behavior).

 

   JCustomEventInit = class external 'CustomEventInit' (JEventInit)
      detail : Variant
   end;
 
   JEventTarget = class external 'EventTarget'
      procedure addEventListener(aType : String; callback : JEventListener; capture  : Boolean = false);
      procedure removeEventListener(aType : String; callback : JEventListener; capture  : Boolean = false);
      function  dispatchEvent(event : JEvent) : Boolean;
   end;

 

Note: Anonymous classes can also be used as lightweight objects (without the external keyword), more akin to records

(custom datatypes in other languages) since it does not include the life-cycle management provided by TObject.