Solved

Multi String Registry Type

Posted on 1998-12-07
13
574 Views
Last Modified: 2010-04-04
How can I retrieve a multi-string value from the registry?
0
Comment
Question by:Llysander
  • 5
  • 3
  • 3
  • +2
13 Comments
 
LVL 44

Expert Comment

by:bruintje
Comment Utility
Hi Llysander,

You can use the GetValues property of a TRefistry object, as it will return a stringlist containing all the datavalues of a key currently selected.

Bruintje.
0
 
LVL 1

Expert Comment

by:BlackDeath
Comment Utility
if you're using delphi 2 upwards, that is...

Black Death
0
 

Author Comment

by:Llysander
Comment Utility
There does not appear to be a GetValues property in TRegistry in Delphi 4.
0
 
LVL 3

Expert Comment

by:philipleighs
Comment Utility
In D4, it's called GetValueNames
0
 

Author Comment

by:Llysander
Comment Utility
GetValueNames just gives me a list of the Value names.  I need to be able to retrieve the value data.  I can do that for most data types, but not multi strings.
0
 
LVL 12

Expert Comment

by:rwilson032697
Comment Utility
Use ReadBinaryData to read the block of data from the registry into a memory block. If this multi string object is essentially an in memory representation of a structure then read it straight into the structure, otherwise you will need to parse it yourself by looking at the length byte and copying the following n bytes into individual strings.

To read it into a structure do this:

TheRegistry.ReadBinaryData('TheKey', TheStructure, sizeof(TheStructure));


Cheers,

Raymond.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:Llysander
Comment Utility
I've tried using a ReadBinary to get the data.  It generates an exception, 'Invalid Data Type';  None of the read methods seem to work either.  I cannot find any registry components that deal with it either, at least ones that don't cost a couple hundred dollars.
0
 

Author Comment

by:Llysander
Comment Utility
Further information on the question:
Delphi 4.02 attempting to retrive the valuedata from the following key.
HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System
ValueName = SystemBiosVersion
DataType = REG_MULTI_SZ

0
 
LVL 44

Expert Comment

by:bruintje
Comment Utility
Hi again,

I've build a little project showing a few things in the registry, it's about 6K so I could email it to you.
It will read keys, values and show data types etc.I'm not certain what you mean bij multistrings but I gues subkeys and their values.

So let me know if you're interested.

Bruintje.
0
 
LVL 3

Expert Comment

by:philipleighs
Comment Utility
A multi string is a chunk of memory where each string is separated by a NULL, and where the whole thing is doubly NULL terminated.

Here is what you want. The function GetMultiStringFromReg fills a string list with the strings, or returns false (or raises exception) otherwise.
It is not the most elegant solution by replacing #0 with #1, but this just makes life easier (can use Pos). StrPas of course treats #0 specially.

It should copy, paste and compile.

procedure MultiStringToStringList(Multi: string; List: TStringList);
  var s: string;
  begin
    while Pos(#1, Multi) > 0 do
      begin
        s := Copy(Multi, 1, Pos(#1, Multi) - 1);
        if s <> '' then
          List.Add(s);
        Delete(Multi, 1, Pos(#1, Multi));
      end;
  end;

function GetMultiStringFromReg(RegPath, RegKey: string; s: TStringList): Boolean;
  var Reg: TRegistry;
      Size: Integer;
      P: PChar;
      DataType: TRegDataType;
      Count: Integer;
begin
  Result := false;
  Reg := TRegistry.Create;
  try
    Reg.RootKey := HKEY_LOCAL_MACHINE;
    if Reg.OpenKey(RegPath, false) then
      begin
        Size := Reg.GetDataSize(RegKey);
        if Size <> -1 then
          begin
            GetMem(P, Size);
            //Originally used ReadBinaryData but got nasty error
            //Use RegQueryValueEx instead
            DataType := rdBinary;
            RegQueryValueEx(Reg.CurrentKey, PChar(RegKey), nil, @DataType, PByte(P), @Size);
            for Count := 0 to Size - 1 do
              if (P + Count)^ = #0 then
                (P + Count)^ := #1;
            MultiStringToStringList(StrPas(P), s);
            FreeMem(P);
            Result := true;
          end;
        Reg.CloseKey;
      end;
  finally
    Reg.Free;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
  var Strings: TStringList;
      Count: Integer;
begin
  Strings := TStringList.Create;
  if GetMultiStringFromReg('Hardware\Description\System', 'SystemBiosVersion', Strings) then
    for Count := 0 to Strings.Count - 1 do
      ShowMessage(Strings[Count]);
end;


0
 

Author Comment

by:Llysander
Comment Utility
Testing Philipleighs example.
Did a quick eye scan through the code, looks good, havn't had a chance to implement it yet.

Philip, if you would please post it as an answer so I can get it off the waiting answer list.
0
 
LVL 44

Expert Comment

by:bruintje
Comment Utility
Oke looks good, but I've implemented this with the valuenames in the project I talked about. It loads all the subkey values into a listbox. So if you would still take a look at it let me know.

Greetz
Bruintje
0
 
LVL 3

Accepted Solution

by:
philipleighs earned 50 total points
Comment Utility
See my comment above.

Cheers,
Phil.

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now