Why do I have to read registry twice ?
Hi,
I'm trying to read classes from the registry. My procedure gets a
file-extension, has to look it up in the registry and find the corresponding
file-type (class ?).
For instance, my procedure receives a ".HTML"-extension, and returns
"Netscape Hypertext Document".
The following code is working... , but I have to call ReadString twice to read a
key. What am I doing wrong ?
--------------------------
Function ReadFileClass (Ext: string): string;
MyReg := TRegistry.Create;
MyReg.RootKey := HKEY_CLASSES_ROOT;
{Get Associated type from registry}
if MyReg.OpenKey (Ext, false)
then
begin
AssTp := MyReg.ReadString (Ext);
// ***** First read
if MyReg.OpenKey (AssTp, false)
then AssTp := MyReg.ReadString (AssTp) //***** Second read !!! Why is
this necessary ???
else
begin
Exception.Create ('Registry-error ???');
end;
MyReg.CloseKey;
{Get File-type Class eg. "Netscape Hypertext Doc."}
if MyReg.OpenKey (AssTp, false)
then FileTp := MyReg.ReadString (AssTp) //***** First Read
else
begin
MessageDlg ('Registry-error ???', mtError, [mbOK], 0);
Exit;
end;
if MyReg.OpenKey (FileTp, false)
then FileTp := MyReg.ReadString (FileTp) //***** Second read
else
begin
MessageDlg ('Registry-error ???', mtError, [mbOK], 0);
Exit;
end;
Result := FileTp;
end;
-----------------------
Thanks in advance.
-----
Alban Hertroys
e-mail: A.G.Hertro...@student.utwente.nl
WWW: http://wit401310.student.utwente.nl/
The Netherlands
-----
...I'll make no subscription to your paradise. (Crass / Stations of the cross)