[Pas2js] How to pass an unknown record to a function as argument?

warleyalex warleyalex at yahoo.com.br
Mon Jun 15 14:49:46 CEST 2020


I use the record structure to map to a table and store/retrieve the data.

type
  TViewsRecord = record
    Category  : string;
    date        : string;
  end;

function JSON2TViewsRecord(const Value: TJSObject): TViewsRecord;
begin
  result.Category   := string(Value['Category']);
  result.date         := string(Value['date']);
end;

function TViewsRecord2JSON(const Value: TViewsRecord): TJSObject;
begin
  result := TJSObject.New;
  result['Category'] := Value.Category;
  result['date']        := Value.date;
end;
-----

------------
...this definition external class

type
  JRec = record

  end;

  TProcColumnNameParams = procedure(columnName: @record);

Of course this not work, I want to write a function and allow the user of
the function to pass a record
that I do not know in advance. 
Then, the idea is to show the columnNames (code autocompletion) of an
unknown DB table.

How to pass an unknown record to a function as argument?

(...)
procedure each(sql: String; callback: TProcColumnNameParams; doneProc:
TProcColumnName); overload;
--------------

Something like to use this:

localDB.each('SELECT date FROM views ORDER BY date ASC',
procedure(columnName: TViewsRecord)
  begin
    console.log(columnName.Category);
    console.log(columnName.date);
  end,
  procedure()
  begin
    console.log('done');
  end);

and so on... // without overloading the external class definition

localDB.each('SELECT * FROM album', procedure(columnName: TAlbumRecord)
begin 
  console.log(columnName.Nome);
  console.log(columnName.CPF); 
end,
procedure() 
begin 
end);






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


More information about the Pas2js mailing list