Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

write binary data in registry

Status
Not open for further replies.

GeoEnaru

Programmer
Mar 15, 2004
7
RO
I need to write a binary data in Registry. I know that the procedure for this is: procedure WriteBinaryData(const Name: String; var Buffer; BufSize: Integer), but I don't know what values are required for Buffer and BufSize. Pls help me with an example.
 
Code:
type
  TMultiRegistry = class ( TRegistry )
  public
    function ReadMultiString ( const name: string; s: TStringList; size: integer ): boolean;
  end;

function TMultiRegistry.ReadMultiString(const name: string; s: TStringList): boolean;
var
  RegData: TRegDataType;
  Info: TRegDataInfo;
  buffer: pchar;
  ptr: pchar;
begin
  s.Clear;
  if GetDataInfo(Name, Info) then begin
    GetMem ( buffer, info.DataSize );
    ReadBinaryData ( name, buffer^, info.DataSize );
    ptr := buffer;
    while ( ptr^ <> #0 ) do begin
      s.Add( ptr );
      inc ( ptr, StrLen(ptr) + 1 );
    end;
    FreeMem ( buffer );
    result := true;
  end
  else
    result := false;
end;

procedure TForm1.Button1Click(Sender: TObject);
const
  Item = 'DriverName';
var
  r: TMultiRegistry;
  ss: TStringList;
begin
  ss := TStringList.Create;
  try
    r := TMultiRegistry.Create;
    r.RootKey := HKEY_LOCAL_MACHINE;
    if r.OpenKey( 'SOFTWARE\Handspring, Inc.\USB\', False ) then
      r.ReadMultiString ( Item, ss );
    listbox.items.assign ( ss );
  finally
    ss.free;
  end;
end;

A long time ago I needed to be able to read out multiline strings in the registry, I couldn't find the thread in which it was posted but I had the code saved and remembered that it made use of the ReadBinaryData, maybe you can work it out from this code here.

[bobafett] BobbaFet [bobafett]

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top