所以我正在尝试在 Delphi 10.4 中编写一个函数,该函数从 SQL 表中取出一个 JSON 文件并在网格中显示其中的所有项目。
其中一个是导致应用程序崩溃的日期格式,所以我很自然地尝试弄清楚它是什么,以便我可以正确格式化它。
然而,我尝试找到它的方法一直显示上述错误:
procedure InjectJSONIntoTable(Query: TFDQuery; MemTable: TFDMemTable; Edit: TEdit);
var
jsonString: string;
jsonArr: TJSONArray;
jsonItem: TJSONObject;
jsonValue: TJSONValue;
i: Integer;
j: Integer;
dummyString: string;
begin
// applies the sql command
Query.SQL.Text := Edit.Text;
Query.Open;
// transforms the sql return back into JSON
jsonString := Query.FieldByName('jdoc').AsString;
jsonArr := TJSonObject.ParseJSONValue(jsonString) as TJSONArray;
// preps the table to receive the data
MemTable.Close;
MemTable.CreateDataSet;
MemTable.Open;
MemTable.Insert;
// appends the data to the table;
for i := 0 to jsonArr.Count -1 do begin
jsonItem := jsonArr.Items[i] as TJSonObject;
for j := 0 to MemTable.Fields.Count - 1 do begin
MemTable.Edit;
jsonValue := jsonItem.GetValue(MemTable.FieldDefs[j].Name);
if jsonValue.ClassType = TDateTime then ShowMessage('tralala');
^ '(' expected but 'THEN' found
MemTable.Fields[j].AsString
:= jsonItem.GetValue(MemTable.FieldDefs[j].Name).Value;
end;
end;
MemTable.Post;
// shows data on the table
end;
也许我是盲人,但老实说我无法弄清楚错误的来源。
我尝试了很多东西,改变了元素的顺序,但是错误要么持续存在,要么出现一堆新错误。
您不能使用
=
来比较类型。使用is
.