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: "Debug Assertion Failed"

Article translations Article translations
Article ID: 922318 - View products that this article applies to.
Expand all | Collapse all

On This Page

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("search text");

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 "Applies to" section.

MORE INFORMATION

Steps to reproduce the problem

  1. Start Visual Studio 2005.
  2. On the File menu, point to New, and then click Project.
  3. 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++.
  4. In the Templates list, click MFC Application.
  5. Type a project name, and then click OK.
  6. Click Next.
  7. In the Application type list, click Single document.
  8. In the left pane, click Generated Classes.
  9. In the Base class box, click CRichEditView, and then click Finish.
  10. On the View menu, click Class View.
  11. In Class view, right-click ProjectName View, and then click Properties.

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

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

    A message appears.
  19. Click OK.
  20. Double-click the text on the right of the cursor.

    You receive the error message that is mentioned in the "Symptoms" section.

REFERENCES

For more information about the CRichEditView class, visit the following Microsoft Developer Network (MSDN) Web site:
http://msdn2.microsoft.com/en-us/library/bcb28z09.aspx
For more information about the CRichEditView::TextNotFound method, visit the following MSDN Web site:
http://msdn2.microsoft.com/en-gb/library/aa990833(vs.80).aspx

Properties

Article ID: 922318 - Last Review: January 12, 2007 - Revision: 1.1
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
Keywords: 
kbtshoot kbcode kbbug KB922318

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com