Cabadam
July 25th, 2003, 11:14 PM
I have a doc/view app w/ a CRichEditView. In it, I define:
void CSyntaxView::ParseLine(long lineNum);
This function starts off by getting the text of the specified line into a CString):
CRichEditCtrl* ctrl = &GetRichEditCtrl();
int lineLen = ctrl->LineLength(lineNum);
char* buf = new char[lineLen];
ctrl->GetLine(lineNum, buf, lineLen);
CString line = buf;
line = line.Left(lineLen);
delete[] buf; ** Problem
buf = NULL;
However, when running in debug, I get an error on the delete line:
DAMAGE: after Normal block (#222) at 0x00337EF0.
I also tried the following:
CRichEditCtrl* ctrl = &GetRichEditCtrl();
int lineLen = ctrl->LineLength(lineNum);
CString line;
ctrl->GetLine(lineNum, line.GetBufferSetLength(lineLen), lineLen);
line.ReleaseBufferSetLength(lineLen);
That gave me the same error - but not until the function returned.
I have tried using both delete[] and just delete and I get the error either way. What am I doing wrong here???
void CSyntaxView::ParseLine(long lineNum);
This function starts off by getting the text of the specified line into a CString):
CRichEditCtrl* ctrl = &GetRichEditCtrl();
int lineLen = ctrl->LineLength(lineNum);
char* buf = new char[lineLen];
ctrl->GetLine(lineNum, buf, lineLen);
CString line = buf;
line = line.Left(lineLen);
delete[] buf; ** Problem
buf = NULL;
However, when running in debug, I get an error on the delete line:
DAMAGE: after Normal block (#222) at 0x00337EF0.
I also tried the following:
CRichEditCtrl* ctrl = &GetRichEditCtrl();
int lineLen = ctrl->LineLength(lineNum);
CString line;
ctrl->GetLine(lineNum, line.GetBufferSetLength(lineLen), lineLen);
line.ReleaseBufferSetLength(lineLen);
That gave me the same error - but not until the function returned.
I have tried using both delete[] and just delete and I get the error either way. What am I doing wrong here???