These are the utility functions and classes in my NiceBase unit, part of the Nice Toolkit for EWB, which is available here.

JSON Objects and String Conversion Utilities

Stringify - convert objects to JSON string

function Stringify( obj : variant ):string;

JSONParse - parse JSON into an object

function JSONParse( s : string ):TExternalObject;

Setting, Getting and Testing Properties of Objects

These utilities simplify the creation, setting, getting and testing properties of TExternalObjects. Normally in EWB you must use Type to define classes of objects or ExternalObjects. These routines take off the kid-gloves and let you quickly access any properites of objects. This can significantly reduce the size of your code but be aware it takes away the safeguards that EWB adds.

newObject – Create an Object

function newObject : TExternalObject;
obj = newObject;

SetProperties - given a.b.c set object.a.b.c=v

procedure SetProperties( obj : variant ; namelist : string ; v: variant );
SetProperties( myobj, 'this.that.the.other', 23 );

setproperty - given a set object.a = v

procedure SetProperty( obj : variant ; name : string ; v : variant );
SetProperty( myobj, 'happiness', 23 );

hasProperty - does property exist

function hasProperty( obj : variant ; name : string):boolean;
if ( hasProperty( myObj, 'index' ) then
   index := GetProperty( myObj, 'index');

getProperty - get a property value

function GetProperty( obj : variant ; name : string ) : variant;
stored = GetProperty( myObj, 'index');

getPropertyNames - list of properties

function GetPropertyNames( obj : TExternalObject ): TStringlist;

CSS and JavaScript Inclusion

There is no easy way to add external CSS to your programs, and it can be challenging to add external JavaScript files and register modules.
These functions simplify all those operations.

procedure addlocalcss( form : TForm; path : string ;
   onsuccess : TNotifyEvent; onfail : TNotifyEvent) ;

procedure addlocaljavascript( form : TForm; path  : string ;
   onsuccess : TNotifyEvent; onfail : TNotifyEvent);

function RegisterJavaScriptModule( v : variant ; module : string ):variant;

JavaScript Console

Browsers have a Debug Console which can be used to log activities and problems. Here you can easily write to that log. See the Format() function below to quickly build a string to send.

consolelog – Write a string to the debug console

procedure consolelog( s : string);

Pascal Ouput Function

Format takes a string (similar to printf in C) which contains terms like %type.precision and returns a formatted string as output. The second argument is an array of arguments to the function.

Format( 'text %usedigits-width.precisionType',[arg1, arg2, .. ])
function format( formatstring : string; args : array of variant ):string;
Format(‘Decimal          = %d', [-123]);
Format(‘Exponent         = %.2e', [12345.678])
Format('Fixed            = %f', [12345.678]);
Format('General          = %.2g', [12345.678]);
Format('Number           = %n', [12345.678]);
Format('Money            = %m', [12345.678]);
Format('String           = %s', ['Hello']);
Format('Unsigned decimal = %u', [123]);
Format('Hexadecimal      = %8x', [140]));

Character Routines

Isdigit – returns true if char is a number

function isdigit( ch : char ):boolean;

TSuperString Class

Delphi has a better TStringlist class which assocations an optional TObject pointer with each element. When you sort the list, the TObjectlist is similarly sorted.

TSuperString Class works mostly similarly, except it does not implement the sorted property.

type
   TSuperStringList = class (TStringList )
   private
      procedure sort1( l, r : integer );
   protected
      sorted : boolean;
   public

      objects : tObjectlist;

      // add with Nill TObject
      function add( s : string ):integer;

      // add with an TObject
      function addobject( s : string ; o : TObject ):integer;

      // delete a string/object
      procedure delete( i : integer );

      // insert a string and nil at a specific location
      procedure insert( index : integer ; s : string );

     // insert a string and TObject at a specific location
      procedure  insertobject( index : integer ; s :string ; o : TObject );

      // mergeinsertobejct – insert a string and object into a previously sorted lsit
      procedure  mergeinsertobject( s :string ; o : TObject );

     // sort the list and its objects
      procedure  sort;

     // clear the list
      procedure clear;

      constructor create;
      destructor destroy;
   end;