Should work (D7), if I understood what you want to do..
Code:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, SHDocVw_TLB, mshtml_tlb, StdCtrls;
type
TForm1 = class(TForm)
WebBrowser1: TWebBrowser;
Button1: TButton;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
procedure MsgHandler(var Msg: TMsg; var Handled: Boolean);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure Tform1.MsgHandler(var Msg: TMsg; var Handled: Boolean);
var
selectionObj: IHTMLSelectionObject;
selectionRange: IHtmlTxtRange;
doc: IHtmlDocument2;
begin
if Msg.message=WM_LBUTTONUP then
if ActiveControl=Webbrowser1 then
if assigned(Webbrowser1.document) then
begin
doc:=Webbrowser1.document as IHtmlDocument2;
selectionObj:=doc.selection;
selectionRange:=selectionObj.CreateRange as IHtmlTxtRange;
if selectionRange.Text<>'' then
Button1.enabled:=true
else
Button1.enabled:=false;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnMessage:=MsgHandler;
Button1.enabled:=false;
Webbrowser1.Navigate('about:some text');
end;
end.