Microsoft KB Archive/922318

= BUG: Error message when an MFC application contains an event handler that uses the CRichEditView::FindText method or the CRichEditView::FindTextSimple method in Visual Studio 2005: &quot;Debug Assertion Failed&quot; =

Article ID: 922318

Article Last Modified on 1/12/2007

-

APPLIES TO


 * Microsoft Visual Studio 2005 Team System Architect Edition
 * Microsoft Visual Studio 2005 Team System Developer Edition
 * Microsoft Visual Studio 2005 Team Foundation
 * Microsoft Visual Studio 2005 Team System Test Edition
 * Microsoft Visual Studio 2005 Standard Edition
 * Microsoft Visual Studio 2005 Professional Edition
 * Microsoft Visual Studio 2005 Express Edition

-





SYMPTOMS
Consider the following scenario:
 * You create a Microsoft Foundation Classes (MFC) application in Microsoft Visual Studio 2005.
 * The base class for the MFC application is the CRichEditView class.
 * The MFC application contains an event handler that uses the CRichEditView::FindText method or the CRichEditView::FindTextSimple method.
 * You compile the MFC application and run the MFC application.
 * You invoke the event handler so that the CRichEditView::FindText method or the CRichEditView::FindTextSimple method returns false. For example, you specify a search string that contains text that is not in the text window.

In this scenario, you may receive the following error message when the CRichEditView::FindText method or the CRichEditView::FindTextSimple method returns false on subsequent function calls:

Debug Assertion Failed!

Program: ...

File: f:\rtm\vctools\vc7libs\ship\atlmfc\src\mfc\viewrich.cpp

Line: 1677



WORKAROUND
To work around this problem, call the CRichEditView::TextNotFound method immediately after a call to the CRichEditView::FindText method or to the CRichEditView::FindTextSimple method returns false. The CRichEditView::TextNotFound method resets the internal search state of the CRichEditView class instance.

The following code example demonstrates how to use the CRichEditView::TextNotFound method. CString szSearch = _T(&quot;search text&quot;);

if (!FindText( szSearch, FALSE, FALSE )) {   // The search string was not found. Call the TextNotFound method. TextNotFound( szSearch ); } else {   // The search string was found. Add code to process the successful search result here. }



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the &quot;Applies to&quot; section.



Steps to reproduce the problem
 Start Visual Studio 2005. On the File menu, point to New, and then click Project. In the Project types list, click Visual C++.

If you do not see the Visual C++ project type, expand Other Languages, and then click Visual C++. In the Templates list, click MFC Application. Type a project name, and then click OK. Click Next.</li> In the Application type list, click Single document.</li> In the left pane, click Generated Classes.</li> In the Base class box, click CRichEditView, and then click Finish.</li> On the View menu, click Class View.</li> In Class view, right-click  View, and then click Properties.

Note In this step,  is a placeholder for the name of the project.</li> In the Properties dialog box, click the Messages button.</li> Click WM_LBUTTONDBLCLK, and then click <Add> OnLButtonDblClk.</li>  In the code window, paste the following code into the OnLButtonDblClk method. CString szSearch = _T(&quot;-&quot;);     // This is the search string. if (!FindText( szSearch, FALSE, FALSE )) {   AfxMessageBox(_T( &quot;Cannot find text.&quot; )); } else AfxMessageBox(_T( &quot;Found text.&quot; )); </li> On the Build menu, click Rebuild Solution.</li> On the Debug menu, click Start Without Debugging.</li> Type some text in the box.

Note Make sure that the text that you type does not contain the search string in step 14.</li> Double-click the text that you typed in step 17.

A message appears.</li> Click OK.</li> Double-click the text on the right of the cursor.

You receive the error message that is mentioned in the &quot;Symptoms&quot; section.</li></ol>

<div class="references_section">