Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Multi String Registry Type

Posted on 1998-12-07
13
580 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
ID: 1349721
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
ID: 1349722
if you're using delphi 2 upwards, that is...

Black Death
0
 

Author Comment

by:Llysander
ID: 1349723
There does not appear to be a GetValues property in TRegistry in Delphi 4.
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 3

Expert Comment

by:philipleighs
ID: 1349724
In D4, it's called GetValueNames
0
 

Author Comment

by:Llysander
ID: 1349725
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
ID: 1349726
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
 

Author Comment

by:Llysander
ID: 1349727
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
ID: 1349728
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
ID: 1349729
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
ID: 1349730
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
ID: 1349731
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
ID: 1349732
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
ID: 1349733
See my comment above.

Cheers,
Phil.

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Create Database on Android via Delphi dbExpress 3 109
Downloading email attachments 2 79
LAN or WAN ? 11 95
PHP preg_replace code convert to Delphi 14 66
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

809 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