在 Win7 RegEdit 中编辑或查看二进制文件,就像 1A 2B 3C 4D 现在我得到一个字符串
str := '1A,2B,3C,4D';
如何将 str 写入 Registry ,并在 Win7 RegEdit 中显示 1A 2B 3C 4D
var
Data: array of Byte; // or whatever binary container you want to use
Reg: TRegistry;
begin
...
SetLength(Data, 4);
Data[0] := $1A;
Data[1] := $2B;
Data[2] := $3C;
Data[3] := $4D;
Reg := TRegistry.Create(KEY_SET_VALUE);
try
Reg.RootKey := ...;
if Reg.OpenKey('...', True) then
begin
Reg.WriteBinaryData('Value', Data[0], 4);
Reg.CloseKey;
end;
finally
Reg.Free;
end;
...
end;
您可以使用TRegistry.WriteBinaryData
. 如果要编写二进制$1A,$2B,$3C,$4D
而不是字符串数据'1A,2B,3C,4D'
,请尝试将其更改为#$1A#$2B#$3C#$4D
.
str := #$1A#$2B#$3C#$4D;
并用于WriteBinaryData
编写注册表:
Reg.WriteBinaryData('KeyName', str, Length(str) * SizeOf(Byte));