[Lazarus] Windows Registry, how do I read data from rdExpandString
Bo Berglund
bo.berglund at gmail.com
Sun Feb 4 20:44:03 CET 2018
I am writing a little Lazarus program to examine the registry values
stored by a program we use.
So far I have only used strings and integers in the registry, and I
have known in advance what type they are. Now I want to make a more
general kind of reader and so I have created a read function like
shown below.
So there is a case construct taht uses the data type reported on each
item, but I don't know what to do about rdExpandString.
In fact I don't know what kind of data may hide behind this data
type...
I would apprecieate to get some clarification on this because googling
has so far not resulted in anything for Pascal.
function ReadRegValues(Root: HKEY; Key: string; List: TStrings):
boolean;
var
Reg: TRegistry;
i: integer;
sVal: string;
siz: integer;
DT: TRegDataType;
BUF: TBytes;
begin
List.Clear;
Result := false;
Reg := TRegistry.Create;
try
Reg.RootKey := Root;
if not Reg.OpenKeyReadOnly(Key) then
exit;
try
Reg.GetValueNames(List);
for i := 0 to List.Count-1 do
begin
sVal := '';
try
if Reg.ValueExists(List[i]) then
begin
DT := Reg.GetDataType(List[i]);
// one of (rdUnknown, rdString, rdExpandString, rdBinary, rdInteger)
case DT of
rdString:
sVal := Reg.ReadString(List[i]);
rdExpandString: What to do here????;
rdBinary:
begin
siz := Reg.GetDataSize(List[i]);
SetLength(BUF, siz);
sVal := '';
Reg.ReadBinaryData(List[i], BUF, siz);
for i := 0 to siz-1 do
sVal := sVal + IntToHex(BUF[i], 2) + ' ';
end;
rdInteger:
sVal := IntToStr(Reg.ReadInteger(List[i]));
end;
end;
List[i] := List[i] + '=' + sVal;
except
end;
end;
Result := true;
except
end;
finally
Reg.Free;
end;
end;
--
Bo Berglund
Developer in Sweden
More information about the Lazarus
mailing list