Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 07-10-2012, 08:53 PM
Zaaka Zaaka is offline
Senior Member
 
Join Date: Aug 2002
Location: Teesside, UK
Posts: 202
Question Is this Possible?

I have a TWebBrowser in my application, but what I need to do is detect when the user selects text on the webpage, so that I can make a button active.

Is this possible, I have tried with onMouseDown/Up but cant seem to get it to work correctly.

Any code samples would be appreciated. I am using XE2
Reply With Quote
  #2  
Old 07-11-2012, 07:00 AM
jm78 jm78 is offline
Member
 
Join Date: Sep 2007
Posts: 36
Default

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.
Reply With Quote
Reply

Tags
select, text, webbrowser, xe2

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 10:07 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.