两个函数怎么用(ReadBinaryData、WriteBinaryData) (50分)

  • 主题发起人 主题发起人 双流星
  • 开始时间 开始时间

双流星

Unregistered / Unconfirmed
GUEST, unregistred user!
请教一下:下面两个函数怎么用,[red]拜托给个例子,解释一下[/red]!
1、[blue]TRegistry.ReadBinaryData[/blue]
function ReadBinaryData(const Name: String;
var Buffer;
BufSize: Integer): Integer;
2、[blue]TRegistry.WriteBinaryData[/blue]
procedure WriteBinaryData(const Name: String;
var Buffer;
BufSize: Integer);
在此先谢了~!
 
uses .., registry;
procedure TForm1.Button2Click(Sender: TObject);
var
Reg: TRegistry;
b,b2:array[0..10] of char;
i,n:integer;
begin
Reg := TRegistry.Create;
b[0]:=#10;
//10
b[1]:='1';
//49
try
Reg.RootKey := HKEY_CURRENT_USER;
if Reg.OpenKey('/Software/Microsoft/Windows/CurrentVersion/RunOnce', True)
then
begin
Reg.WriteBinaryData('MyApp',b,2);
n:=Reg.ReadBinaryData('MyApp',b2,10);
showmessage(inttostr(n));
for i:=0 to n-1 do
showmessage(inttostr(integer(b2)));
end;

finally
Reg.CloseKey;
Reg.Free;
inherited;
end;
end;
 
谢谢~
不过,请问要怎样才能 读/存 “字符串”?
 
Readstring,WriteString
查看 TRegistry 的帮助文档。
procedure TForm1.WMEndSession(var Message: TWMEndSession);
var
Reg: TRegistry;
begin
Reg := TRegistry.Create;
try
Reg.RootKey := HKEY_CURRENT_USER;
if Reg.OpenKey('/Software/Microsoft/Windows/CurrentVersion/RunOnce',
True)
then
Reg.WriteString('MyApp','"' + ParamStr(0) + '"');
finally
Reg.CloseKey;
Reg.Free;
inherited;
end;
end;
 
谢谢你:jszjd
我想问的是怎样用WriteBinaryData 和 ReadBinaryData 读写字符串!
结合你的例子及参照了别人的代码,得出了下面的结果!
uses Registry;
procedure TForm1.Button1Click(Sender: TObject);
var
fReg: TRegistry;
fBuffer:array[0..1024] of char;
aBuffer:array[0..1024] of char;
begin
fReg := TRegistry.Create;
StrLCopy(fBuffer,pchar('大富翁的小伙计!'),Sizeof(fBuffer));
try
fReg.RootKey := HKEY_CURRENT_USER;
if fReg.OpenKey('/Software/BinaryData', True) then
begin
fReg.WriteBinaryData('MyApp',fBuffer,Sizeof(fBuffer));
fReg.ReadBinaryData('MyApp',aBuffer,Sizeof(aBuffer));
ShowMessage(String(aBuffer));
end;
finally
fReg.CloseKey;
fReg.Free;
end;
end;
 
贴子结了~
 
后退
顶部