Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Reading Multi String values from the Registry

261 views
Skip to first unread message

Russ Wright

unread,
Jul 1, 2001, 11:40:24 AM7/1/01
to
Delphi 2 and Windows 2000

Using Regedit to check the value type this type is shown as REG_MULTI_SZ
When you modify it with REGEDIT , it shows a "Edit Binary Value"

TRegistry.ReadBinaryData fails with an error, "this datatype is in correct"

TRegistry.DataTypes are listed as rdUnknown, rdBinary, rdExpandString,
rdString and rdInteger

is there a workaround for Delphi 2 ?

Thanks
Russ

Russ Wright

unread,
Jul 1, 2001, 11:43:37 AM7/1/01
to

Thomas Nelvik

unread,
Jul 1, 2001, 12:47:20 PM7/1/01
to


Since the datatype shouldn't matter when reading, I guess
it is the TRegistry class that causes this trouble.
If you could try the function below, and and already have
a TRegistry instance, you can pass it the TRegistry.CurrentKey
as the "aKey" parameter. (Example at bottom of msg.)

{--------------------}
function Reg_ReadMultiSz(aKey: HKEY; const aValueName: string;
aStrings: TStrings): Boolean;
var
DataType,
DataSize: Longword;
Data: Pointer;
P: PChar;
begin
Result := RegQueryValueEx(aKey, PCHAR(aValueName), NIL, @DataType,
NIL, @DataSize) = ERROR_SUCCESS;
if Result then
begin
GetMem(Data, DataSize);
try
Result := RegQueryValueEx(aKey, PCHAR(aValueName), NIL, NIL,
Data, @DataSize) = ERROR_SUCCESS;
if Result then
begin
aStrings.Clear;
P := Data;
while P^ <> #0 do
begin
AStrings.Append(P);
Inc(P, StrLen(P) + 1);
end;
end;
finally
FreeMem(Data);
end;
end;
end;
{--------------------}

Usage example:

procedure TForm1.Button1Click(Sender: TObject);
var
List: TStringList;
begin
List := TStringList.Create;
try
with TRegistry.Create do
try
{ Change these registry entries
to your own suitable values }
RootKey := HKEY_CURRENT_USER;
OpenKeyReadOnly('software\company\application');
Reg_ReadMultiSz(CurrentKey, 'some_multisz_value', List);
finally
CloseKey;
Free;
end;
ShowMessage(List.Text);
finally
List.Free;
end;
end;
{-----}

HTH
Regards
-ThomasN


Russ Wright

unread,
Jul 1, 2001, 1:20:00 PM7/1/01
to
Thomas , it's works like a charm
Thank You again

Russ

"Thomas Nelvik" <thomas...@chello.no> wrote in message
news:3b3f53b4_2@dnews...

0 new messages