-3

在 Win7 RegEdit 中编辑或查看二进制文件,就像 1A 2B 3C 4D 现在我得到一个字符串

str := '1A,2B,3C,4D';

如何将 str 写入 Registry ,并在 Win7 RegEdit 中显示 1A 2B 3C 4D

4

2 回答 2

4
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;
于 2012-10-10T03:50:23.843 回答
0

您可以使用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));
于 2012-10-10T03:40:46.280 回答