D10 到 DXE5:TJSONBool.Create(False) 和 JSONObj.ToJSON 的等价物是什么?

D10 to DXE5: what's the equivalent of TJSONBool.Create(False) and JSONObj.ToJSON?

以下代码在 D10 西雅图编译正常,但我安装了 D10 的电脑坏了。然后我需要使用 DXE5 在我的项目中做一个小的更新,但不能编译,因为命令 TJSONBool.Create(False)JSONObj.ToJSON 存在。

TJSONBool.Create(False)JSONObj.ToJSONDXE5 上分别等效于什么?

uses
 Data.DBXJSON, SHFolder;

function GetSpecialFolderPath(folder : integer) : string;
 const
   SHGFP_TYPE_CURRENT = 0;
 var
   path: array [0..MAX_PATH] of char;
 begin
   if SUCCEEDED(SHGetFolderPath(0,folder,0,SHGFP_TYPE_CURRENT,@path[0])) then
     Result := path
   else
     Result := '';
 end;

procedure ChangeChromeSetting(const ATarget, Avalue: string);
var
  specialfolder: integer;
  pathchrome: String;
  JSONObj, ObjIpp: TJSONObject;
  JSONPair: TJSONPair;
  OldValue: string;
begin
  specialFolder := CSIDL_LOCAL_APPDATA;
  pathchrome := GetSpecialFolderPath(specialFolder);
  pathchrome := pathchrome + '\Google\Chrome\User Data\Local State';

 if fileexists(pathchrome) then
  begin
    JSONObj := TJSONObject.ParseJSONValue(TFile.ReadAllText(pathchrome)) as TJSONObject;
    if not Assigned(JSONObj) then Exit; {raise Exception.Create('Cannot read file: ' + pathchrome);}
    try
      OldValue := JSONObj.GetValue<string>(ATarget);
       if OldValue = '' then
               Exit;
      if not SameText(OldValue, Avalue) then
      begin
        JSONPair := JSONObj.Get(ATarget);
        JSONPair.JsonValue.Free;
        JSONPair.JsonValue := TJSONString.Create(Avalue);

        ObjIpp := TJSONObject.Create;
        ObjIpp.AddPair('enabled', TJSONBool.Create(False));
        JSONObj.AddPair('hardware_acceleration_mode', ObjIpp);

        TFile.WriteAllText(pathchrome, JSONObj.ToJSON);
      end;
    finally
      JSONObj.Free;
    end;
  end;
end;

//////////////////////  USAGE /////////////////////////

ChangeChromeSetting('hardware_acceleration_mode_previous', 'false');

TJSONBoolTJSONAncestor.AsJSON 在 XE5 中还不存在。 ToJSON 在 XE7 中添加,TJSONBool 在 10.0 Seattle 中添加。

在旧版本中,使用 TJSONTrue/TJSONFalse and TJSONObject.ToString 代替:

ObjIpp.AddPair('enabled', TJSONFalse.Create);
... 
TFile.WriteAllText(pathchrome, JSONObj.ToString);