You are not logged in.
Pages: 1
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
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
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
Pages: 1