#1 2015-06-05 13:56:10

Alvar Mayor
Member
Registered: 2015-06-05
Posts: 5

Loading records in a TClientDataSet

I'm new to mORMot.
Starting from sample 28 i try to build a server and a client with data mapped on a SQL Server 2008 R2.
I must populate a TDBGrid on the client side with the records of a table on my DB.
I can load the records in a TSQLTableJson (i see TSQLTableJSON.RowCount is the correct number), but I can't fin a way to put these record in a standard TClientDataset for my TDBGrid.

Someone can help?
This is a part of my code

var
  strJSON: RawUTF8;
  tbJSON : TSQLTableJson;
  fSQLDataset: TSynSQLTableDataSet;

begin
  fModel := DataModel;
  try
    fClient := TSQLHttpClientWinHTTP.Create('localhost',SERVER_PORT,fModel);
    try
      tbJSON := fClient.ExecuteList([TPerson],'select * from person');
      MemoPerson.Lines.Add('tbJSON.RowCount = '+IntToStr(tbJSON.RowCount));

      //... here i need at least the conversion from TSQLTableJson to strJSON (RawUTF8), but i will appreciate other hints 
      //(simple hints! I'm totally new!)


      //what I try to do:
      DSPerson.DataSet := JSONToDataSet(nil, strJSON);
      DSPerson.DataSet := JSONToClientDataSet(fSQLDataset, fJSON, fClient);

Offline

#2 2015-06-05 14:10:02

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,606
Website

Re: Loading records in a TClientDataSet

Why not just use TSynSQLTableDataSet constructors?

See

    /// initialize the virtual TDataSet from a TSQLTable
    // - WARNING: the supplied TSQLTable instance shall remain available
    // all the time the returned TSynSQLTableDataSet instance is used, unless
    // the TableShouldBeFreed property is set to true or CreateOwnedTable()
    // constructor is used instead
    // - with non-Unicode version of Delphi, you can set aForceWideString to
    // force the use of WideString fields instead of AnsiString, if needed
    // - the TDataSet will be opened once created
    constructor Create(Owner: TComponent; Table: TSQLTable
      {$ifndef UNICODE}; ForceWideString: boolean=false{$endif}); reintroduce;
    /// initialize the virtual TDataSet owning a TSQLTable
    // - this constructor will set TableShouldBeFreed to TRUE
    // - with non-Unicode version of Delphi, you can set aForceWideString to
    // force the use of WideString fields instead of AnsiString, if needed
    // - the TDataSet will be opened once created
    constructor CreateOwnedTable(Owner: TComponent; Table: TSQLTable
      {$ifndef UNICODE}; ForceWideString: boolean=false{$endif}); reintroduce;

Offline

#3 2015-06-05 14:18:08

Alvar Mayor
Member
Registered: 2015-06-05
Posts: 5

Re: Loading records in a TClientDataSet

Found a way ...

  strJSON := fClient.RetrieveListJSON(TPerson,'ID > 0',[],'');
  DSPerson.DataSet := JSONToClientDataSet(self, strJSON, fClient);
  DSPerson.DataSet.Open;

Offline

Board footer

Powered by FluxBB