BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Using TRegistry in BCB 5

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage)
View previous topic :: View next topic  
Author Message
Paulus Wallus
Guest





PostPosted: Thu May 17, 2007 2:59 am    Post subject: Using TRegistry in BCB 5 Reply with quote



I've been attempting to read the list of keys beneath the Root Key using
TRegistry from the registry. I don't seem to grasp how to do this:

What I am currently doing:
-----------------------------------8<-----------------------------------
Reg->RootKey = HKEY_CLASSES_ROOT;
Reg->Access = KEY_READ;
Reg->Access;
Root = RegViewTreeView->Items->Add(NULL, "HKEY_CLASSES_ROOT");
Error = "INFO: " + SetRootNode(Reg, Root, 4, 1);
-----------------------------------8<-----------------------------------

SetRootNode Function (nothing special)

-----------------------------------8<-----------------------------------
AnsiString TRegManForm::SetRootNode(
TRegistry *Reg,
TTreeNode *Root,
int Normal,
int Error)
{
AnsiString Return;
if(Reg->OpenKeyReadOnly(NULL))
{
SearchFromLoc(Reg, Root);
Root->ImageIndex = Normal;
Root->SelectedIndex = Normal;
}
else
{
switch((unsigned int)Reg->RootKey)
{
case HKEY_CLASSES_ROOT:
Return.sprintf("could not open HKEY_CLASSES_ROOT");
break;
case HKEY_CURRENT_USER:
Return.sprintf("could not open HKEY_CURRENT_USER");
break;
case HKEY_LOCAL_MACHINE:
Return.sprintf("could not open HKEY_LOCAL_MACHINE");
break;
case HKEY_USERS:
Return.sprintf("could not open HKEY_USERS");
break;
case HKEY_CURRENT_CONFIG:
Return.sprintf("could not open HKEY_CURRENT_CONFIG");
break;
}
Root->ImageIndex = Error;
Root->SelectedIndex = Error;
}
return Return;
}
-----------------------------------8<-----------------------------------

Why I did it this way

I set the root key first (one needs too of course)

-----------------------------------8<-----------------------------------

bool __fastcall OpenKeyReadOnly(const AnsiString Key);

Description

Call OpenKeyReadOnly to make a specified key the current key. Key is the
name of the key to open. If Key is NULL, the CurrentKey property is set
to the key specified by the RootKey property.

Key is opened with the security access value KEY_READ.

OpenKey returns true if the key is successfully opened and CurrentKey is
set to the key.

Note: after a successful call to OpenKeyReadOnly the Access property of
the registry component is automatically changed to KEY_READ, regardless
of what that property was set to prior to the method call.
-----------------------------------8<-----------------------------------

It says it the current key is set to the RootKey Property so this is
opening the root key. However it doesn't suceed at opening it read only
(or even open the key with just OpenKey). So... how should I do this?

Stephen - somewhat baffled.
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Thu May 17, 2007 4:55 am    Post subject: Re: Using TRegistry in BCB 5 Reply with quote



"Paulus Wallus" <someone (AT) someplace (DOT) com> wrote in message
news:Xns9932B7041B7DCMY2XX3120891 (AT) 207 (DOT) 105.83.66...

Quote:
Reg->Access = KEY_READ;

That will get overwritten by OpenKeyReadOnly().

Quote:
Reg->Access;

That line as no effect.

Quote:
if(Reg->OpenKeyReadOnly(NULL))

Specify an empty string instead (and make sure no key is already open
before calling SetRootNode()):

if( Reg->OpenKeyReadOnly("") )

Better would be to specify a slash by itself to explicitially indicate
the root key:

if( Reg->OpenKeyReadOnly("\\") )


Gambit
Back to top
Stephen Phillips
Guest





PostPosted: Thu May 17, 2007 6:55 am    Post subject: Re: Using TRegistry in BCB 5 Reply with quote



"Remy Lebeau \(TeamB\)" <no.spam (AT) no (DOT) spam.com> wrote in news:464b99f4$1
@newsgroups.borland.com:

Quote:
if(Reg->OpenKeyReadOnly(NULL))

Specify an empty string instead (and make sure no key is already open
before calling SetRootNode()):

if( Reg->OpenKeyReadOnly("") )

Better would be to specify a slash by itself to explicitially indicate
the root key:

if( Reg->OpenKeyReadOnly("\\") )

Thanks.. that is what I was missing, apparently the behavior is not as

advertised (SIGH). I should have known this too. I appreciate your
correcting me there. (the extra code was for trying to figure out what was
going wrong now you pointed it out I feel silly).

Stephen
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Thu May 17, 2007 7:49 am    Post subject: Re: Using TRegistry in BCB 5 Reply with quote

"Stephen Phillips" <someone (AT) someplace (DOT) com> wrote in message
news:Xns9932DF0D31B67MY2XX3120891 (AT) 207 (DOT) 105.83.66...

Quote:
Thanks.. that is what I was missing, apparently the behavior
is not as advertised (SIGH).

Actually, it is - provided that an empty string really is being passed
to OpenKeyReadOnly() to begin with. You really shouldn't pass NULL
directly to an AnsiString variable/parameter, as it may or may not be
interpreted as an int instead of a char*. If that happened, you would
be opening the wrong key. Using an actual string literal (or a
variable) ensures that does not happen.


Gambit
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.