Board index » cppbuilder » TRegistry->WriteBool() throws exception

TRegistry->WriteBool() throws exception


2005-07-22 01:27:34 PM
cppbuilder68
Hi all,
I know this might be trivial, but I couldn't locate any post on this with
search, so I'll have to ask it.
I'm using TRegistry to access the Registry, when I tried to use
WriteBool(ValName, Value), BCB always give me an exception upon compiling:
Project TCPrinter.exe raised an exception class ERegistryException with
message 'Failed to set data for 'AutoMode''. Process stopped.
The problem sourced from this block of code:
void __fastcall TForm1::AutoCheckClick(TObject *Sender)
{
TRegistry *reg = new TRegistry;
reg->WriteBool("AutoMode", AutoCheck->Checked);
delete reg;
}
AutoCheck is a TCheckBox, AutoMode is the Registry Value Name.
The strange thing is, it's thrown upon compiling, I haven't triggered the
event yet. I do have a reg->ReadBool() in the constructor, but it never
caused any problem. I deleted the reg at the end of the constructor, so it's
not object conflict problem...
Anyone have any idea what's wrong? Thanks in advance.
 
 

Re:TRegistry->WriteBool() throws exception

Ehrm, how embarassing...I only realised the proble after posting: I have to
open the key first...sorry, and please ignore this post.
"Choykw" < XXXX@XXXXX.COM >wrote in message
Quote
Hi all,

I know this might be trivial, but I couldn't locate any post on this with
search, so I'll have to ask it.

I'm using TRegistry to access the Registry, when I tried to use
WriteBool(ValName, Value), BCB always give me an exception upon compiling:

Project TCPrinter.exe raised an exception class ERegistryException with
message 'Failed to set data for 'AutoMode''. Process stopped.

The problem sourced from this block of code:

void __fastcall TForm1::AutoCheckClick(TObject *Sender)
{
TRegistry *reg = new TRegistry;
reg->WriteBool("AutoMode", AutoCheck->Checked);
delete reg;
}

AutoCheck is a TCheckBox, AutoMode is the Registry Value Name.

The strange thing is, it's thrown upon compiling, I haven't triggered the
event yet. I do have a reg->ReadBool() in the constructor, but it never
caused any problem. I deleted the reg at the end of the constructor, so
it's not object conflict problem...

Anyone have any idea what's wrong? Thanks in advance.

 

Re:TRegistry->WriteBool() throws exception

"Choykw" < XXXX@XXXXX.COM >wrote in message
Quote
The problem sourced from this block of code:
You did not set the RootKey property (it is set to HKEY_CURRENT_USER by
default), but more importantly you did not call either CreateKey() or
OpenKey() before calling WriteBool(). Where do you expect the value to be
written to if you don't first tell Tregistry where to place the value?
Quote
The strange thing is, it's thrown upon compiling
No, it is not. It is thrown at runtime. The project's code is not executed
during compiling.
Quote
I haven't triggered the event yet.
Yes, you must have.
Quote
I do have a reg->ReadBool() in the constructor, but it never caused any
problem.
It would if you do not call OpenKey() or CreateKey() first.
Gambit
 

{smallsort}