我给你转帖一个,我就是用它实现了二进制值的写入!
上面是写入,下面是读入:
var
Reg : TRegistry;
Buf : array [1..4] of Byte;
//因为你写入的数据是00 00 00 01,四个字节,所以数组大小定义为4了;
begin
Reg:=TRegistry.Create;
try
Reg.RootKey := HKEY_CURRENT_USER;
Reg.OpenKey('/Software/Microsoft/Windows/CurrentVersion/Policies/Explorer', True);
//这里给数组赋值,对应关系看下面
// 00 00 00 01
// Buf[1] Buf[2] Buf[3] Buf[4]
Buf[1] := 00;
Buf[2] := 00;
Buf[3] := 00;
Buf[4] := 01;
Reg.WriteBinaryData('NoSaveSettings', Buf , SizeOf(Buf));
//WriteBinaryData的第三个参数是你要写入的节字数大小,SizeOf(Buf)是得到数组Buf的大小(即是4)。
//如果你将这句改为
//Reg.WriteBinaryData('NoSaveSettings', Buf , 2);
//那么写入的只是Buf[1]和Buf[2],如果打开注册表看,这个键的值是00 00
finally
Reg.Free;
end;
----------------------------------------------
var
Reg : TRegistry;
Buf : array [1..4] of Byte;
BufSize: Integer;
begin
Reg:=TRegistry.Create;
try
Reg.RootKey := HKEY_CURRENT_USER;
Reg.OpenKey('/Software/Microsoft/Windows/CurrentVersion/Policies/Explorer', True);
BufSize := Reg.GetDataSize('NoSaveSettings');
if BufSize <> -1 then
Reg.ReadBinaryData('NoSaveSettings', Buf , BufSize);
//.............
finally
Reg.Free;
end;