Page 1 of 1

place the selected text on the page into a variable

Posted: Mon Sep 21, 2020 2:17 pm
by dvbss11
how to put in a variable the selected text on the page?

Code: Select all

TOnTextSelectionChanged         = procedure(Sender: TObject; const browser: ICefBrowser; const selected_text: ustring; const selected_range: PCefRange) of Object;
which event will connect to?

Re: place the selected text on the page into a variable

Posted: Mon Sep 21, 2020 2:19 pm
by dvbss11

Code: Select all

procedure TBrauserChrom.Chrom_TextSelectionChanged(Sender: TObject; const browser: ICefBrowser; const selected_text: ustring; const selected_range: PCefRange);
begin
   FHelpTextSelection:= selected_text;
   showmessage(FHelpTextSelection);
end;
did not work like that

Re: place the selected text on the page into a variable

Posted: Mon Sep 21, 2020 2:28 pm
by salvadordf
Hi,

The TChromium.OnTextSelectionChanged event is only available in OSR mode. Browsers in "normal" mode will not get that event.

You also have to consider that all TChromium events are executed in a CEF thread. This means that you have to protect the variables with synchronization objects like critical sections

Remember that VCL is not thread safe and your application shouldn't create, destroy or modify any VCL control inside TChromium's events.

Re: place the selected text on the page into a variable

Posted: Mon Sep 21, 2020 2:37 pm
by dvbss11
https://prnt.sc/ul6uge

in the mini browser there is a copy when selected I do not have it
what does OSR mean?

Re: place the selected text on the page into a variable

Posted: Mon Sep 21, 2020 3:04 pm
by salvadordf
dvbss11 wrote: Mon Sep 21, 2020 2:37 pm https://prnt.sc/ul6uge
in the mini browser there is a copy when selected I do not have it
That menu option is added automatically by Chromium when the user can copy something from the document.
dvbss11 wrote: Mon Sep 21, 2020 2:37 pm what does OSR mean?
It's the "off-screen rendering" mode used by the SimpleOSRBrowser demo. It gives you total control of the browser events and it uses the TChromium.OnPaint event to send raw bitmap data with the web contents. It's much slower but you have total control.