【发布时间】:2021-03-05 09:09:43
【问题描述】:
我注意到TJSONObject.AddPair 函数的结果是Self 而不是新创建的对象:
例如,在System.JSON 单元中我看到以下代码:
function TJSONObject.AddPair(const Str: string; const Val: string): TJSONObject;
begin
if (not Str.IsEmpty) and (not Val.IsEmpty) then
AddPair(TJSONPair.Create(Str, Val));
Result := Self;
end;
我期待这样的事情:
function TJSONObject.AddPair(const Str: string; const Val: string): TJSONObject;
begin
if (not Str.IsEmpty) and (not Val.IsEmpty) then
Result := AddPair(TJSONPair.Create(Str, Val));
else
Result := nil;
end;
我觉得这很不寻常,是 Delphi XE7 的错误还是他们这样做的任何技术/实际原因?
【问题讨论】:
-
你在当前对象上是正常的,通过总结给当前对象添加对的便捷方法确认。否则,你可以使用
TJSONPair.Create
标签: json delphi delphi-xe7