[Fwd: [lazarus] TRegistry: OpenKey, Access]

Luis R. Hilario luis at luis-digital.8m.com
Thu Feb 1 21:07:31 EST 2001


"Luis R. Hilario" wrote:
> 
> Hi,
> 
> New: property Access.
> 
> I am also working with: OpenKey, but I have a problem.
> OpenKey is not complete, but it works:
> 
> function TRegistry.OpenKey(const Key: string; CanCreate: Boolean):
> Boolean;
> Var
>   KeyP: PChar;
>   PHandle: PHKEY;
>   Disposition: LPDWord;
>   SecurityAttributes: LPSECURITY_ATTRIBUTES;
> 
> begin
> KeyP := @Key[1];
> SecurityAttributes := Null;
> 
> If CanCreate then
>    Result := RegCreateKeyEx(fRootKey,
>                             KeyP,
>                             0,
>                             '',
>                             REG_OPTION_NON_VOLATILE,
>                             fAccess,
>                             SecurityAttributes,
>                             PHandle,
>                             Disposition) = ERROR_SUCCESS else
>    Result := RegOpenKeyEx(fRootKey,
>                           KeyP,
>                           0,
>                           fAccess,
>                           PHandle) = ERROR_SUCCESS;
> 
> If Result then fCurrentKey := PHandle^;
> end;
> 
> The problem is with the test program:
> 
> if Not Reg.OpenKey(SubKey, True) then         // If it happens an error
> the following lines they execute...
>     Writeln('Error Abriendo Key: ', SubKey);  // ...if there is no an
> error the following lines not they execute.
>     Writeln(Reg.CurrentKey, '/', Reg.RootKey);
>     Reg.CloseKey;
>     Reg.free;
>     Writeln(Reg.CurrentKey, '/', Reg.RootKey);
> 
> It is working like:
> 
> if Not Reg.OpenKey(SubKey, True) then
>   Begin                                 // <--- OjO (Eye :)
>     Writeln('Error Abriendo Key: ', SubKey);
>     Writeln(Reg.CurrentKey, '/', Reg.RootKey);
>     Reg.CloseKey;
>     Reg.free;
>     Writeln(Reg.CurrentKey, '/', Reg.RootKey);
>   end;                                  // <--- OjO
> 
> Somebody knows what is happening here?
> 
> I am going to change to Winbug and to prove something, but any aid is
> appreciated.

Some made tests:
"If then" is working well.
If use "Writeln" before OpenKey, OpenKey does not open and creates a key
and leaves with an error.

Example:
Writeln(SubKey);
if Not Reg.OpenKey(SubKey, True) then... // An error here.

-- 
 |-----------------------------|
| Luis R. Hilario               |
| http://www.luisdigital.2y.net |
 |-----------------------------|

To: "lazarus at miraclec.com" <lazarus at miraclec.com>
Subject: [lazarus] TRegistry: OpenKey, Access
From: "Luis R. Hilario" <luis at luis-digital.8m.com>
Date: Thu, 01 Feb 2001 18:26:55 -0300
Organization: Luis Digital
Reply-To: lazarus at miraclec.com
Resent-Date: Thu, 1 Feb 2001 17:44:53 -0500
Resent-From: lazarus at miraclec.com
Resent-Message-ID: <rVsUTB.A.e3G.kbee6 at harding.miraclec.com>
Resent-Sender: lazarus-request at miraclec.com
Sender: luis at harding.miraclec.com

Hi,

New: property Access.

I am also working with: OpenKey, but I have a problem.
OpenKey is not complete, but it works:

function TRegistry.OpenKey(const Key: string; CanCreate: Boolean):
Boolean;
Var
  KeyP: PChar;
  PHandle: PHKEY;
  Disposition: LPDWord;
  SecurityAttributes: LPSECURITY_ATTRIBUTES;

begin
KeyP := @Key[1];
SecurityAttributes := Null;

If CanCreate then
   Result := RegCreateKeyEx(fRootKey,
                            KeyP,
                            0,
                            '',
                            REG_OPTION_NON_VOLATILE,
                            fAccess,
                            SecurityAttributes,
                            PHandle,
                            Disposition) = ERROR_SUCCESS else
   Result := RegOpenKeyEx(fRootKey,
                          KeyP,
                          0,
                          fAccess,
                          PHandle) = ERROR_SUCCESS;

If Result then fCurrentKey := PHandle^;
end;

The problem is with the test program:

if Not Reg.OpenKey(SubKey, True) then         // If it happens an error
the following lines they execute...
    Writeln('Error Abriendo Key: ', SubKey);  // ...if there is no an
error the following lines not they execute.
    Writeln(Reg.CurrentKey, '/', Reg.RootKey);
    Reg.CloseKey;
    Reg.free;
    Writeln(Reg.CurrentKey, '/', Reg.RootKey);

It is working like:

if Not Reg.OpenKey(SubKey, True) then
  Begin                                 // <--- OjO (Eye :)
    Writeln('Error Abriendo Key: ', SubKey);
    Writeln(Reg.CurrentKey, '/', Reg.RootKey);
    Reg.CloseKey;
    Reg.free;
    Writeln(Reg.CurrentKey, '/', Reg.RootKey);
  end;                                  // <--- OjO

Somebody knows what is happening here?

I am going to change to Winbug and to prove something, but any aid is
appreciated.

-- 
 |-----------------------------|
| Luis R. Hilario               |
| http://www.luisdigital.2y.net |
 |-----------------------------|

_________________________________________________________________
     To unsubscribe: mail lazarus-request at miraclec.com with
                "unsubscribe" as the Subject
    archives at http://www.miraclec.com/list_archives/lazarus






More information about the Lazarus mailing list