🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Refresh Windows Registry

#6799
From: Remy Lebeau (TeamB)
Date: Mon, 11 Apr 2005 18:42
77 lines
3256 bytes
"Grety" <valid@emailaddress.com> wrote in message
news:42594bd9@newsgroups.borland.com...

> I open the Regedit in Win98 for example
> do the changes and See :-? Nothing happed, but when I
> press F5 (Refresh Button) the changes Apply.
> Now I want to know can I programmically do this job,
> using Refresh()? there is no Refresh Function in MyReg,
> How?

You don't need one.  When you write to the Registry, the values are
available immediately.  What you describe is merely a display issue in the
Registry Editor, not the Registry itself.  If you run the same test on an
NT-based system without making any chanes to your code, you will see the
Editor update the display automatically as expected.

>    TRegistry *MyReg=new TRegistry();
>    MyReg->RootKey=HKEY_CURRENT_USER;
>    MyReg->OpenKey("somewhere",true);
>    MyReg->WriteString("1",Edit1->Text);
> //   MyReg->Refresh
>    delete MyReg;

That code is not error safe.  If OpenKey() fails, WriteString() will throw
an exception, bypassing your 'delete' statement and thus the memory for the
TRegistry object will be leaked.  You should be checking the return value of
OpenKey(), and also wrapping the 'new' and 'delete' statements with an
exception handler, or at least use a std::auto_ptr object.  For example:

    try
    {
        TRegistry *MyReg = new TRegistry;
        try
        {
            MyReg->RootKey = HKEY_CURRENT_USER;
            if( MyReg->OpenKey("somewhere",true) )
            {
                MyReg->WriteString("1",Edit1->Text);
                MyReg->CloseKey();
            }
            else
                // could not open/create the key...
        }
        __finally {
            delete MyReg;
        }
    }
    catch(const Exception &)
    {
        // an error occured...
    }

or:

    #include <memory>

    try
    {
        std::auto_ptr<TRegistry> MyReg(new TRegistry);

        MyReg->RootKey = HKEY_CURRENT_USER;
        if( MyReg->OpenKey("somewhere",true) )
        {
            MyReg->WriteString("1",Edit1->Text);
            MyReg->CloseKey();
        }
        else
            // could not open/create the key...
    }
    catch(const Exception &)
    {
        // an error occured...
    }


Gambit
Technical Details
Message-ID: <425ac492$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news2.google.com!newsread.com!news-xfer.newsread.com!nntp.abs.net!newsfeed2.telusplanet.net!newsfeed.telus.net!cyclone.bc.net!newshub.sdsu.edu!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <42594bd9@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,e6e3b9d83755cc0d
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <42594bd9@newsgroups.borland.com>
Subject: Re: Refresh Windows Registry
Date: Mon, 11 Apr 2005 11:42:17 -0700
Lines: 79
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 68.69.17.41
Message-ID: <425ac492$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1113244818 68.69.17.41 (11 Apr 2005 11:40:18 -0800)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news2.google.com!newsread.com!news-xfer.newsread.com!nntp.abs.net!newsfeed2.telusplanet.net!newsfeed.telus.net!cyclone.bc.net!newshub.sdsu.edu!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail