Discussion:
Tripping Over the Radio
(too old to reply)
James Watson
2008-05-03 16:49:37 UTC
Permalink
The following code triggers an access violation (with BCB6):

extern AnsiString defpath;
//[...]
AnsiString GetText(CMyClass &classinstance, bool trueorfalse)
{
AnsiString path;
if(Form5->V1Radio->Checked) path = defpath + "\\V1\\";
//VIOLATION OCCURS IN THE ABOVE LINE
else if(Form5->V2Radio->Checked) path = defpath + "\\V2\\";
//[...]
}

The error is triggered by the accessing of the Checked property of the
V1Radio component, as I discovered by changing the if...else code to:

if(Form5->V1Radio->Checked) //VIOLATION HERE
{
//[...]
path = defpath + "\\V1\\";
} else if(Form5->V2Radio->Checked)
{
//[...]
path = defpath + "\\V2\\";
}

I get a popup window labelled 'Debugger Exception Notification', and
containing the text:

Project Project1.exe raised exception class
EAccessViolation with message 'Access
violation at address 00444A82 in module
'Project1.exe'. Read of address 6F500A00'.
Process stopped. Use Step or Run to continue.

At the practical level, I have already solved my problem by creating
the static variable

static AnsiString specificDirectory;

which I define in an OnClick event as "\\V1\\" or "\\V2\\" according
to whether V1Radio or V2Radio is being clicked. Within the
above-mentioned function the problematic code is replaced with

AnsiString path = defpath + specificDirectory;

Nevertheless, I would like to know what is wrong with my earlier code.

Thanks to whomever will help me.

James Watson
Bob Gonder
2008-05-03 19:58:41 UTC
Permalink
Post by James Watson
AnsiString GetText(CMyClass &classinstance, bool trueorfalse)
{
AnsiString path;
if(Form5->V1Radio->Checked) path = defpath + "\\V1\\";
//VIOLATION OCCURS IN THE ABOVE LINE
Just a guess that Form5 has been destructed.
Might be a bit more obvious if Path were a member of Form5.

AnsiString Form5::GetPath()
{
if(V1Radio->Checked)
return defpath + "\\V1\\";
return defpath;
}
AnsiString GetText(CMyClass &classinstance, bool trueorfalse)
{
AnsiString path = Form5->GetPath();
DreamChaser
2008-05-03 19:57:53 UTC
Permalink
Just a stupid question, but is the Form5 header included in this file
before GetText()?
DC
Post by James Watson
extern AnsiString defpath;
//[...]
AnsiString GetText(CMyClass &classinstance, bool trueorfalse)
{
AnsiString path;
if(Form5->V1Radio->Checked) path = defpath + "\\V1\\";
//VIOLATION OCCURS IN THE ABOVE LINE
else if(Form5->V2Radio->Checked) path = defpath + "\\V2\\";
//[...]
}
The error is triggered by the accessing of the Checked property of the
if(Form5->V1Radio->Checked) //VIOLATION HERE
{
//[...]
path = defpath + "\\V1\\";
} else if(Form5->V2Radio->Checked)
{
//[...]
path = defpath + "\\V2\\";
}
I get a popup window labelled 'Debugger Exception Notification', and
Project Project1.exe raised exception class
EAccessViolation with message 'Access
violation at address 00444A82 in module
'Project1.exe'. Read of address 6F500A00'.
Process stopped. Use Step or Run to continue.
At the practical level, I have already solved my problem by creating the
static variable
static AnsiString specificDirectory;
which I define in an OnClick event as "\\V1\\" or "\\V2\\" according to
whether V1Radio or V2Radio is being clicked. Within the above-mentioned
function the problematic code is replaced with
AnsiString path = defpath + specificDirectory;
Nevertheless, I would like to know what is wrong with my earlier code.
Thanks to whomever will help me.
James Watson
James Watson
2008-05-04 00:06:30 UTC
Permalink
[...]

Thank you, Bob and DreamChaser. That was rather embarrassing. I put
the function in question above the form's contructor precisely because
it didn't refer to any of the form's components. Then I got so
accustomed to it being there that it didn't occur to me to question
its location after that characteristic changed! Oh, well ... sorry to
have bothered you.

James Watson
DreamChaser
2008-05-06 06:19:32 UTC
Permalink
Post by James Watson
[...]
Thank you, Bob and DreamChaser. That was rather embarrassing. I put
the function in question above the form's contructor precisely because
it didn't refer to any of the form's components. Then I got so
accustomed to it being there that it didn't occur to me to question its
location after that characteristic changed! Oh, well ... sorry to have
bothered you.
James Watson
James, I subscribe to the "Did you check the fuse?" concept. And trust
me, we have ALL done it. Happy Coding :)

DC

Remy Lebeau (TeamB)
2008-05-05 05:19:53 UTC
Permalink
Post by James Watson
if(Form5->V1Radio->Checked) path = defpath + "\\V1\\";
//VIOLATION OCCURS IN THE ABOVE LINE
Then either 'Form5' or 'V1Raidio' contains an invalid pointer value at the
time.


Gambit
James Watson
2008-05-05 16:07:43 UTC
Permalink
Post by Remy Lebeau (TeamB)
Post by James Watson
if(Form5->V1Radio->Checked) path = defpath + "\\V1\\";
//VIOLATION OCCURS IN THE ABOVE LINE
Then either 'Form5' or 'V1Raidio' contains an invalid pointer value at the
time.
Thanks, Gambit. This way of expressing the problem underscores how
obvious the solution should have been to me. The truth is that I very
rarely use pointers consciously (i.e., whilst thinking of them as
pointers, as opposed to, say, 'ways of accessing a component').

Take care.

James Watson
Loading...