Board index » cppbuilder » TRegistry: how to Write/Read the default value of a key

TRegistry: how to Write/Read the default value of a key

How can I read or write the defaul tvalue of a key?
I tried to access it with the GetValueNames() method, but Iget an access
violation. This is the code I used:

   bool keyOK;
   TStrings *keyValues = NULL;
   TRegistry &regKey = *new TRegistry();
   regKey.RootKey = HKEY_LOCAL_MACHINE;
   if (regKey.KeyExists("MyKey"))
      // do something
   else {
      keyOK = regKey.OpenKey("MyKey", true);
      if (keyOK) {
         try {
            regKey.GetValueNames(keyValues);
            regKey.WriteString(keyValues->Strings[0], "MyValue");
         }
        catch(...) {
            throw;
        }
    }

I get the AV after the execution of GetValueNames.
Why?

Thanks, Rodolfo

 

Re:TRegistry: how to Write/Read the default value of a key


Hello Rodolfo,

Rodolfo Cappa <rodca...@tin.it> schreef in berichtnieuws
8g64hj$b...@bornews.borland.com...

Quote
> How can I read or write the defaul tvalue of a key?
> I tried to access it with the GetValueNames() method, but Iget an access
> violation. This is the code I used:

Hmm, I don't use the registry much so I leave that to someone else to
check<g>, but using TStrings isn't advisable since this is an abstract
class, and also you don't allocate memory for it, what certainly will result
in an AV.
So do something like:

bool keyOK;
TStringList *keyValues = new TStringList;
...
// registry code here
...
delete keyValues;

Hope this helped...;-))

Quote
> Thanks, Rodolfo

--
Greetings from overcast Amsterdam

                Jan

email: bijs...@worldonline.nl
http://home.worldonline.nl/~bijster

Other Threads