🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #1877

Re: problems of saving a registry key to a file

#1877
From: han
Date: Tue, 29 May 2007 02:38
74 lines
3471 bytes
Remy,

Thank you so much for your help. I did not have openkey function before. I add this later because savekey gives me error. So I thought I am going to see if it open key OK. I tried your way, it is still the same. I tried directly using savekey without using openkey function, still the same problem. I alse make sure the file does not exist before I am running the code.

Let me know if you have any other suggestion. Thanks.

han zhang

"Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> wrote:
>
>"han" <hanzhangusa@yahoo.com> wrote in message
>news:465a6397@newsgroups.borland.com...
>
>> I am trying to save a key to a file using SaveKey, but I always
>> fail. The open key is successfull, but saveKey is not successful,
>> The file is generated, but the size of the file is zero. The
>following
>> is my code.
>
>The key you are specifying has no leading '\\' in it, so it is going
>to be treated as relative to whatever the currently active key is.
>When you call OpenKey(), there is no active key yet, so your key
>string is relative to the RootKey and thus succeeds in being opened if
>it exists.  But when you then call SaveKey() afterwards, TRegistry
>tries to open your key again, but relative to the key you already
>opened, and thus fails to find the new key.  In other words, SaveKey()
>is looking for
>"Software\\XXXCompany\\Settings\\ViewForms\\Software\\XXXCompany\\Sett
>ings\\ViewForms", which obviously does not exist.
>
>The best solution is to get rid of the OpenKey() altogether, since
>SaveKey() opens the key anyway:
>
>    TRegistry *myRegistry = new TRegistry;
>    try
>    {
>        if(
>!myRegistry->SaveKey("Software\\XXXCompany\\Settings\\ViewForms",
>"tempReg") )
>            Application->MessageBox("save key error", NULL, MB_OK);
>    }
>    __finally
>    {
>        delete myRegistry;
>    }
>
>If you want to use OpenKey() to validate the key's existance
>beforehand, then specify an empty string when calling SaveKey() so
>that it obtains a second handle to the same key that is already open:
>
>    TRegistry *myRegistry = new TRegistry;
>    try
>    {
>        if(
>myRegistry->OpenKey("Software\\XXXCompany\\Settings\\ViewForms",
>false) )
>        {
>            if( !myRegistry->SaveKey("", "tempReg") )
>                Application->MessageBox("save key error", NULL,
>MB_OK);
>        }
>        else
>            Application->MessageBox("open key error", NULL, MB_OK);
>    }
>    __finally
>    {
>        delete myRegistry;
>    }
>
>
>Gambit
>
>
Technical Details
Message-ID: <465b9222$2@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <465a6397@newsgroups.borland.com> <465b4af1$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,321743db05a8d51
X-Google-Attributes: gid10cc67,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: "han" <hanzhangusa@yahoo.com>
Sender: "han" <hanzhangusa@yahoo.com>
Reply-To: "han" <hanzhangusa@yahoo.com>
Subject: Re: problems of saving a registry key to a file
Newsgroups: borland.public.cppbuilder.nativeapi
X-User-Info: 64.143.221.52     
References: <465a6397@newsgroups.borland.com> <465b4af1$1@newsgroups.borland.com>
NNTP-Posting-Host: 207.105.83.66
Message-ID: <465b9222$2@newsgroups.borland.com>
Date: 28 May 2007 19:38:26 -0700
X-Trace: newsgroups.borland.com 1180406306 207.105.83.66 (28 May 2007 19:38:26 -0700)
Lines: 75
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail