James Watson
2008-05-03 16:49:37 UTC
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
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