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!

Multi-String in the Registry? 1

Status
Not open for further replies.

BobbaFet

Programmer
Feb 25, 2001
903
0
0
NL
Hi all,

I'm trying to read data from the registry but I cant read it with any of the read types of Delphi or so it seems. Windows XP says that its of the Multi-String type, does anyone of you know how I can read it out?

Thanx in advance,

[bobafett] BobbaFet [bobafett]

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com
 
What exactly are you trying to read? What kind of error are you getting and can you copy and paste the code that fails to the forum?

Andrew
 
its a stringlist what im trying to read. code is just regular but it keeps returning that im requesting the wrong kind of data.

uses blablabla, Registry;

procedure TForm1.button1click(Sender: TObject);
var R: TRegistry;
begin
R := TRegistry.Create;
R.RootKey := HKEY_LOCAL_MACHINE;
R.OpenKey('\Software\Microsoft\Windows\CurrentVersion\RunOnce',
False);
Memo1.Text := R.ReadString('Classic'); // here it goes wrong says wrong data kind.
R.CloseKey;
R.Free;



[bobafett] BobbaFet [bobafett]

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com
 
Can you do a copy and paste of your actual code into the forum? The code you supplied looks as though you keyed it in.

Is the error a compiler or run-time error? What is the actual error message?

Have you used Regedit to examine exactly what is in the Registry for this particular key? What Type does Regedit give for 'Classic' ?

Andrew

 
Ok, so this is the message:

Project Project1,exe raised exception class ERegistryException with message 'Invalid data type for 'Action''. Process stoppen. Use Step or Run to continue.

And this is the actual code:

Code:
procedure TForm1.RetrieveClick(Sender: TObject);
var R: TRegistry;
begin
R := TRegistry.Create;
R.RootKey := HKEY_LOCAL_MACHINE;
if R.OpenKey('SOFTWARE\PopCap\BookWorm\Scores',False) then
        begin
        ActionScore.Text  := R.ReadString('Action');
        BestScore.Text    := R.ReadString('Best');
        ClassicScore.Text := R.ReadString('Classic');
        LongestScore.Text := R.ReadString('Longest');
        end
        else
        MessageDlg('No scores found.',mtError,[mbOk],0);
R.CloseKey;
R.Free;
end;

Can you help me out?

[bobafett] BobbaFet [bobafett]

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com
 
BobbaFet, You haven't answered these questions:-

>Have you used Regedit to examine exactly what is in the >Registry for this particular key?

>What Type does Regedit give for 'Classic' ?

However, as you originally supplied incorrect information by saying it failed on 'Classic' we actually need to know what Type does Regedit give for 'Action'.


Andrew
 
Hi BobbaFet,

According to your Delphi version, you may do
this :

MyStringList.Delimiter := '#';

Reg.WriteStr( MyStringList.DelimitedText );

In this way you save the string list using a
string key that you can revert to a list using the
same delimiter.

Cheers,

Andrew
 
Hey TowerBase,

All these values are according to RegEdit of WinXP of the Multi-String type when I look at it in the value editor.
Indicated in the RegEdit main screen under type it says:
REG_MULTI_SZ.

Hey DeerBear, Im not trying to write them, Ijust want to read them out.

Hope you can help,

[bobafett] BobbaFet [bobafett]

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com
 
And I forgot to say that these keys contain string lists.

[bobafett] BobbaFet [bobafett]

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com
 
It appears that Delphi 7 does not contain Registry support for REG_MULTI_SZ strings. These seem to be quite rare - I had to search for some time to find one in my Registry.

However, it is not difficult to add support for REG_MULTI_SZ strings - thanks to inheritance.

Define a new class called TMultiRegistry which will be derived from TRegistry and will contain one new function to Read REG_MULT_SZ strings:
Code:
type
  TMultiRegistry = class ( TRegistry )
  public
    function ReadMultiString ( const name: string; s: TStringList; size: integer ): boolean;
  end;
Now code up the function that will actually read the REG_MULTI_SZ and convert it to a StringList.
Code:
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;
You may want to put some extra error handling in there. Now to call the function. In this example, I read the driver name for my Handspring PDA from the Registry and put it into a list box.
Code:
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;

Hope that helps.

Andrew
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top