[Pas2js] array of const

warleyalex warleyalex at yahoo.com.br
Sat Feb 16 15:22:01 CET 2019


Hum, yes. I can not use "array of const" to pass parameters, just because it
shows the status "not implemented" in my old pas2js 1.2. 
=======================
TSQLRest = class

end;

TSQLRecord = class(TPersistent)
  protected
  public
    constructor CreateAndFillPrepare(aClient: TSQLRest;
      const FieldNames, SQLWhere: string;
      const BoundsSQLWhere: array of const);  //Error: not yet implemented:
:TPasArrayType [20171005235610] array of const
end;

constructor TSQLRecord.CreateAndFillPrepare(aClient: TSQLRest;
  const FieldNames, SQLWhere: string;
  const BoundsSQLWhere: array of const);
begin
//
end;   
=======================
Indeed, one important missing feature was the "array of const" to pass
parameters in pas2js. 

Anyway, I did another test, this one, I'm passing an "array of metaclass"
type as argument to subroutine, I didn't know this works in my pas2js 1.2,
for instance: 
----------------//
/// return the database Model corresponding to the mORMot server
function GetModel(aRoot: string=SERVER_ROOT): TSQLModel;
begin
  result := TSQLModel.Create([TSQLAuthGroup, TSQLAuthUser],aRoot);
end;
-----------------//
...we need to set the TSQLAuthGroup and TSQLAuthUser classes, these classes
should be part of the model, these tables contain the available user access
rights for the mORMot authentication, those classes
inherits from the TSQLRecord, in which uses the "array of const" as
parameter feature.

====================================
test I
-------
TSQLRecord = class(TPersistent)
  protected
  public
    //constructor CreateAndFillPrepare(aClient: TSQLRest;
    //  const FieldNames, SQLWhere: string;
    //  const BoundsSQLWhere: array of const);  
end;

TSQLAuthGroup = class(TSQLRecord)
  protected
    fIdent: string;
    fAccessRights: string;
    fSessionTimeOut: integer;
  published
    /// the access right identifier, ready to be displayed
    // - the same identifier can be used only once (this column is marked as
    // unique via a "stored AS_UNIQUE" (i.e. "stored false") attribute)
    property Ident: string read fIdent write fIdent;
    /// the number of minutes a session is kept alive
    property SessionTimeout: integer read fSessionTimeOut write
fSessionTimeOut;
    /// a textual representation of a TSQLAccessRights buffer
    property AccessRights: string read fAccessRights write fAccessRights;
  end;

/// table containing the Users registered for authentication
  TSQLAuthUser = class(TSQLRecord)
  protected
    fLogonName: string;
    fPasswordHashHexa: string;
    fDisplayName: string;
    //procedure SetPasswordPlain(const Value: string);
  public
    /// able to set the PasswordHashHexa field from a plain password content
    // - in fact, PasswordHashHexa := SHA256('salt'+PasswordPlain) in UTF-8
    //property PasswordPlain: string write SetPasswordPlain;
  published
    /// the User identification Name, as entered at log-in
    // - the same identifier can be used only once (this column is marked as
    // unique via a "stored AS_UNIQUE" - i.e. "stored false" - attribute),
and
    // therefore indexed in the database (e.g. hashed in
TSQLRestStorageInMemory)
    property LogonName: string read fLogonName write fLogonName;
   /// the User Name, as may be displayed or printed
    property DisplayName: string read fDisplayName write fDisplayName;
    /// the hexa encoded associated SHA-256 hash of the password
    property PasswordHashHexa: string read fPasswordHashHexa write
fPasswordHashHexa;
  end;

type
  TSQLRecordClass = class of TSQLRecord;

  TSQLModel = class
    protected
      fRoot: string;
    public
      constructor Create(const Tables: array of TSQLRecordClass;
         const aRoot: string='root');
   end;

constructor TSQLModel.Create(const Tables: array of TSQLRecordClass;
  const aRoot: string);
var
    i: integer;
begin
  for i:= low(Tables) to high(Tables) do
    console.log(Tables[i]);
end;

function GetModel(aRoot: string): TSQLModel;
begin
  result := TSQLModel.Create([TSQLAuthGroup,TSQLAuthUser],aRoot);
end;

(...)
 GetModel('root');
====================================
It seems array of metaclass as argument works great here.




--
Sent from: http://pas2js.38893.n8.nabble.com/


More information about the Pas2js mailing list