Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function DataSet.JsonToDataset(aJSON : string; Arg: TProc<TDataset>): String;
- var
- JObj: TJSONArray;
- vConv : TCustomJSONDataSetAdapter;
- FmemoryDataset: TFDMemTable;
- begin
- Result := aJSON;
- if (aJSON = EmptyStr) then
- begin
- Exit;
- end;
- FmemoryDataset:= TFDMemTable.Create(nil);
- JObj := TJSONObject.ParseJSONValue(aJSON) as TJSONArray;
- vConv := TCustomJSONDataSetAdapter.Create(Nil);
- try
- vConv.Dataset := FmemoryDataset;
- vConv.UpdateDataSet(JObj);
- if Assigned(Arg) then
- Arg(FmemoryDataset);
- finally
- vConv.Free;
- JObj.Free;
- FreeAndNil( FmemoryDataset );
- end;
- end;
- function DataSet.JsonToMemoryDataset<TJsonString>(AJsonString: String; Arg: TProc<TDataset>): TDataset;
- begin
- Result := self;
- JsonToDataset(AJsonString,Arg);
- end;
- function DataSet.TryField<T>(const aFieldName: String; Arg: T): Variant;
- var
- FField: TField;
- begin
- try
- FFIeld:= FindField(aFieldName);
- finally
- if FField = nil then
- Result := Any.From(Arg).AsVariant
- else
- Result:= FField.Value;
- end;
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement