Article View: borland.public.cppbuilder.nativeapi
Article #15023Re: What's the best way to set data in Registry?
From: Remy Lebeau (TeamB)
Date: Tue, 22 Jul 2003 07:19
Date: Tue, 22 Jul 2003 07:19
46 lines
2713 bytes
2713 bytes
"Phuoc Can HUA" <home}a+t{huaonline.com> wrote in message
news:oprso8ohk2bq7az6@newsgroups.borland.com...
> Since I don't want to check each single entry I put
> all in one try{} and as soon as one fails then it goes
> to the block for default values.
That is not a very good design approach. There are several different
reasons why a particular value may fail at any time, not all of them are
data failures. You shouldn't need to force everything to defaults just
because one particular value fails for any number of reasons.
> The problem is whenever a new version has a new
> parameter then it will reset all the settings in the first run :-(
Then you will just have to test each value individually. If you want an
elegant solution, then why not just wrap the reading in a method that
handles the details for you? It can do the existence checking and default
value storing and such as appropriate. For example:
// assuming Reg is a TRegistry that is a member of the form
// and is already opened to the target registry key
int __fastcall TForm1::RegReadInteger(const AnsiString &Name, int
Default)
{
try
{
if( !Reg->ValueExists(Name) )
Reg->WriteInteger(Name, Default);
return Reg->ReadInteger(Name);
}
catch(Exception&) {}
return Default;
}
Then you can call the reading method whenever needed instead of performing
the Registry code directly:
int i = RegReadInteger("Some Value", 10);
You can expand on this to include reading functions for strings, boolean,
etc. as well.
Gambit
Technical Details
Message-ID:
<3f1ce441@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-09!supernews.com!64.152.100.70.MISMATCH!sjc70.webusenet.com!news.webusenet.com!cyclone.bc.net!logbridge.uoregon.edu!xmission!nntp.infostrada.it!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<oprso8ohk2bq7az6@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,c19edcb7bdc4d9c7 X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-07-22 00:40:06 PST From: "Remy Lebeau \(TeamB\)" <gambit47@yahoo.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <oprso8ohk2bq7az6@newsgroups.borland.com> Subject: Re: What's the best way to set data in Registry? Date: Tue, 22 Jul 2003 00:19:32 -0700 Lines: 49 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 NNTP-Posting-Host: 207.175.226.26 Message-ID: <3f1ce441@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1058858049 207.175.226.26 (22 Jul 2003 00:14:09 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-09!supernews.com!64.152.100.70.MISMATCH!sjc70.webusenet.com!news.webusenet.com!cyclone.bc.net!logbridge.uoregon.edu!xmission!nntp.infostrada.it!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail