gpt4 book ai didi

json - D10 到 DXE5 : what's the equivalent of TJSONBool. 创建(False)和 JSONObj.ToJSON?

转载 作者:行者123 更新时间:2023-12-03 19:24:54 26 4
gpt4 key购买 nike

下面的代码在D10西雅图上编译得很好,但是我安装了D10的电脑坏了。然后我需要使用 DXE5 在我的项目中进行小更新,但无法编译,因为命令 TJSONBool.Create(False)JSONObj.ToJSON 存在。

DXE5上,什么相当于TJSONBool.Create(False)JSONObj.ToJSON

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 中尚不存在。 XE7 中添加了 ToJSON,10.0 Seattle 中添加了 TJSONBool

在旧版本中,使用 TJSONTrue/TJSONFalseTJSONObject.ToString相反:

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

关于json - D10 到 DXE5 : what's the equivalent of TJSONBool. 创建(False)和 JSONObj.ToJSON?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47745697/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com