#1 2017-04-18 14:24:03

burimm
Member
Registered: 2017-04-18
Posts: 3

SynDBExploreFrame how to properly fill Dataset

Hi,
I have started to experiment with mormot - with sample 12 - SynDBExplorer.
In this segment of code:

with Frame do begin
              fJSONBuffer := Rows.FetchAllAsJSON(false);
              Stop := Timer.Stop;
              Table := TSQLTableJSON.Create('',pointer(fJSONBuffer),length(fJSONBuffer));
              fGrid := TSQLTableToGrid.Create(DrawGrid,Table,nil);
              fGrid.SetAlignedByType(sftCurrency,alRight);
              fGrid.OnValueText := OnText;
              fGrid.SetFieldFixedWidth(100);
              fGrid.FieldTitleTruncatedNotShownAsHint := true;
              DrawGrid.Options := DrawGrid.Options-[goRowSelect];
              DrawGrid.OnDblClick := self.OnGridDblClick;
              RowsCount := Table.RowCount;
              RowsSize := length(fJSONBuffer);
end;

I want to create a dataset and fill it so I can use it with my grid. Firstly just in read only mode.
During my experimenting i came to this (after declaring  F: TStringStream and lDataSet  : TDataSet)

with Frame do begin
              //....... the same code as above
              //....... and just added my code before end

              F:=TStringstream.Create('',TEncoding.UTF8);
              fGrid.Table.GetJSONValues( F,True);
              lDataSet:=JSONToDataSet(Self, F.DataString);
              dbGrid1.DataSource.DataSet := lDataSet;
              F.Free;
end 
// this works ok and very fast

My question is: How to do it without using  DrawGrid and fGrid as in this sample ??

Offline

#2 2017-04-18 14:43:00

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

Re: SynDBExploreFrame how to properly fill Dataset

JsonToDataSet() is a stand-alone function, which does not use any DrawGrid.
Just supply your JSON to JsonToDataSet.
For instance, the RawUTF8 returned by Rows.FetchAllAsJSON(false).

Offline

#3 2017-04-18 20:06:13

burimm
Member
Registered: 2017-04-18
Posts: 3

Re: SynDBExploreFrame how to properly fill Dataset

Thanks @ab,

it works great if I put here:

begin
fJSONBuffer := Rows.FetchAllAsJSON(false);
lDataSet:=JSONToDataSet(Self, fJSONBuffer);
dbGrid1.DataSource.DataSet := lDataSet;
//....other lines non changed
.......
end

but, if I put here:

begin
fJSONBuffer := Rows.FetchAllAsJSON(false);
//....other lines non changed
.......

lDataSet:=JSONToDataSet(Self, fJSONBuffer);
dbGrid1.DataSource.DataSet := lDataSet;
end

there is an error:
TsynSQLTableDataset1: Field name missing

if i click BtnExec again - the same error but the number is incremented like
TsynSQLTableDataset2: Field name missing

Who is changing fJSONBuffer?

Offline

Board footer

Powered by FluxBB