Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.

How to add search bar?

Post Reply
User avatar
danicarla2
Posts: 19
Joined: Mon Oct 01, 2018 6:01 pm
Location: Brazil

How to add search bar?

Post by danicarla2 »

Hi guys!

First of all congratulations for the beautiful work, I should have migrated before to DCEF4

I'm trying to add a search bar, but I have very little knowledge in Delphi.

In the examples I did not find anything close that could help me, could someone give me a hint of where to find a tutorial or a way to learn to do it?
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to add search bar?

Post by salvadordf »

Hi,

You would have to use these procedures :
  • TChromium.Find
  • TChromium.StopFinding
The CEF3 code comments for TChromium.Find are these :

Code: Select all

  ///
  // Search for |searchText|. |identifier| must be a unique ID and these IDs
  // must strictly increase so that newer requests always have greater IDs than
  // older requests. If |identifier| is zero or less than the previous ID value
  // then it will be automatically assigned a new valid ID. |forward| indicates
  // whether to search forward or backward within the page. |matchCase|
  // indicates whether the search should be case-sensitive. |findNext| indicates
  // whether this is the first request or a follow-up. The cef_find_handler_t
  // instance, if any, returned via cef_client_t::GetFindHandler will be called
  // to report find results.
  ///
And the code comments for TChromium.StopFinding are these :

Code: Select all

  ///
  // Cancel all searches that are currently going on.
  ///
You may also have to use the TChromium.OnFindResult event which has these code comments :

Code: Select all

  ///
  // Called to report find results returned by cef_browser_host_t::find().
  // |identifer| is the identifier passed to find(), |count| is the number of
  // matches currently identified, |selectionRect| is the location of where the
  // match was found (in window coordinates), |activeMatchOrdinal| is the
  // current position in the search results, and |finalUpdate| is true (1) if
  // this is the last find notification.
  ///
Modify one of the demos and add a TEdit to enter text.
Then add 2 buttons that would call TChromium.Find and TChromium.StopFinding respectively.

When you click the "Find" button you will see that the document highlights the text you tried to search.
When you want to clear the highlighted text then you should call the "StopFinding" button.

If you need to know where are the find results then use TChromium.OnFindResult.
User avatar
danicarla2
Posts: 19
Joined: Mon Oct 01, 2018 6:01 pm
Location: Brazil

Re: How to add search bar?

Post by danicarla2 »

I realized that unfortunately my question is about delphi, and I am php developer this seems very complicated to me.
I will delve into some Delphi course...

Thank you for the quick reply :)
Post Reply