I want to find out if the TChromiumFMX browser component contains text that the user has selected, and if so, retrieve that text, without the user having to copy it to the clipboard (ctrl-c) first.
To improve on TLama's answer: If you're not using ShowMessage, the anonymous procedure will not always have completed before Button1Click is exited, hence often yielding no results (or too late). Therefore a Done := true as the last line of the procedure can be checked for to see if the value has been retrieved:
procedure TForm1.Button1Click(Sender: TObject);
var Done: boolean;
begin
Done := false;
Chromium1.Browser.GetFocusedFrame.VisitDomProc(
procedure(const document: ICefDomDocument)
begin
SelectedText := document.SelectionAsText;
Done := true
end
);
while not Done do Application.ProcessMessages
end;