TObject

Top  Previous  Next

TObject

 

In traditional Object Pascal all classes inherit from a root type called TObject. This was also the case for Delphi Web Script, from which Smart Pascal evolved. In order to better be able to import classes written in Javascript - which is extremely important with regards to having full support for the DOM (document object model) and the full spectrum of JavaScript modules - dependency on TObject as the root of all class types had to be altered. See for instance, TVariant in the example bellow:

 

mytoggle_plus1TObject: the root type of SmartMS

var TObject={

   $ClassName: "TObject",

   $Parent: null,

   ClassName: function (s) { return s.$ClassName },

   ClassType: function (s) { return s },

   ClassParent: function (s) { return s.$Parent },

   $Init: function () {},

   Create: function (s) { return s },

   Destroy: function (s) { for (var prop in s) if (s.hasOwnProperty(prop)) delete s.prop },

   Destroy$: function(s) { return s.ClassType.Destroy(s) },

   Free: function (s) { if (s!==null) s.ClassType.Destroy(s) }

};

 

var Round = Math.round;

function $New(c) { var i={ClassType:c}; c.$Init(i); return i };

/// TW3CustomBrowserAPI = class (TObject)

 

var TW3CustomBrowserAPI = {

   $ClassName:"TW3CustomBrowserAPI",

   $Parent:TObject

   ,$Init:function ($) {

      TObject.$Init($);

   }

   ,Destroy:TObject.Destroy

};

 

/// TVariant = class (TObject)

var TVariant = {

   $ClassName:"TVariant",

   $Parent:TObject

   ,$Init:function ($) {

      TObject.$Init($);

   }

   /// function TVariant.AsFloat(const aValue: Variant) : Float

   ,AsFloat:function(aValue) {

      var Result = 0;

      if (VarIsValidRef(aValue)) {

         Result = Number(aValue);

      }

      return Result

   }

   /// function TVariant.AsInteger(const aValue: Variant) : Integer

   ,AsInteger:function(aValue$1) {

      var Result = 0;

      if (VarIsValidRef(aValue$1)) {

         Result = parseInt(aValue$1,10);

      }

      return Result

   }

   /// function TVariant.AsString(const aValue: Variant) : String

   ,AsString:function(aValue$2) {

      var Result = "";

      if (VarIsValidRef(aValue$2)) {

         Result = ""+aValue$2;

      }

      return Result

   }

   /// function TVariant.IsNumber(const aValue: Variant) : Boolean

   ,IsNumber:function(aValue$3) {

      var Result = false;

      

    if (aValue$3 == nullreturn false;

    if (aValue$3 == undefined) return false;

    if (typeof(aValue$3) === "number"return true;

  return Result

   }

   /// function TVariant.IsString(const aValue: Variant) : Boolean

   ///  [line: 1280, column: 25, file: System.Types]

   ,IsString:function(aValue$4) {

      var Result = false;

      

    if (aValue$4 == nullreturn false;

    if (aValue$4 == undefined) return false;

    if (typeof(aValue$4) === "string"return true;

  return Result

   }

   ,Destroy:TObject.Destroy

};

 

 

 

 Simple example

 

True object inheritance

JavaScript does not support true OOP in the ordinary sense of the word, which makes it exceedingly difficult for classical web-designers to create reusable components or manage large scale projects. But Smart delivers full OOP running under JavaScript!. Our compiler technology generates a real-life VMT (virtual method table) in JavaScript, which means that you can write objects and inherit from them just like you do in Delphi. This gives you a tremendous advantage over classical web developers that must rely on a wide scope of JavaScript libraries, libraries that rarely co-exist without causing browser instabilities. With Smart this is not the case – here you can enjoy the same freedom of rapid, object oriented software architecture as you would under Delphi or Visual Studio.