Title: Browser CopyCat
Question: You've all used the TWebbrowser control - every wondered how to copy the selected text to the clipboard without using OLE??
Answer:
You may think that the answer to this problem is extremely simple. Just simply select the text and hit CTRL-C and hey presto you have the text on the clipboard - All well and good, but what happens when you want to put this command into a menu?? Use the SendKeys procedure that has been posted as an article on delphi3000.com - I hear you cry...NO - what follows is a much easier and elegant solution:
procedure CopyTextToClipboard;
var
selection: OleVariant;
Range: OleVariant;
document: OleVariant;
begin
//check there some text in the control
if VarIsEmpty(webView.Document) then
exit;
// Get the document
document := webView.Document;
try
// Get the selected text
selection := Document.selection;
// Create the range of the text so that...
range := selection.CreateRange;
// ...you can get the text and put on the clipboard
Clipboard.AsText := range.Text
except
end;
end;