I get an error after changing search pattern using TextSearch

Q:

I’m using PDFViewCtrl class, but with my own text search dialog. I initialize it with the following code

m_txtSearch.Begin(*(m_view->GetDoc()), "", pdftron::PDF::TextSearch::TextSearchModes::e_highlight);

where m_txtSearch is

`

pdftron::PDF::TextSearch m_txtSearch;

`

Then the user enters the text they want to find, then clicks Find. I then call SetPattern with the entered text, and run the search, with the code below.

`

m_txtSearch.SetPattern(search_string);

pdftron::PDF::SearchResult result = m_txtSearch.Run();
`

But the call to Run throws with the following exception.

The instance hasn’t been initialized yet.


A:

The problem is Begin is failing, it is actually returning false. This is because the pattern is empty. To get the code above to work, just pass any sort of text into the pattern.``

m_txtSearch.Begin(*(m_view->GetDoc()),“temp”, pdftron::PDF::TextSearch::TextSearchModes::e_highlight);