Re: TWebBrowser questions

From: Alex Taylor (basswar_at_vnet.hu)
Date: 05/18/04


Date: Tue, 18 May 2004 08:28:58 +0200

TWebBrowser already has the standard mouse and keyboard events
implemented but they are not published. You can simply publish it and
they will be available. Here is the source:

unit MyWebBrowser;

interface

uses
   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
   OleCtrls, SHDocVw;

type
   TMyWebBrowser = class(TWebBrowser)
   private
     { Private declarations }
   protected
     { Protected declarations }
   public
     { Public declarations }
     Constructor Create(AOwner:TComponent);Override;
   published
     { Published declarations }
     Property OnMouseMove;
     Property OnMouseDown;
     Property OnMouseUp;
     Property OnClick;
     Property OnDblClick;
     Property OnKeyDown;
     Property OnKeyUp;
   end;

procedure Register;

implementation

Constructor TMyWebBrowser.Create(AOwner:TComponent);
Begin
   Inherited;

   ControlStyle:=ControlStyle-[csNoStdEvents];
   ControlStyle:=ControlStyle+[csCaptureMouse,csClickEvents,csDoubleClicks];
End;

procedure Register;
begin
   RegisterComponents('MyComp', [TMyWebBrowser]);
end;

end.

This doesn't ensure the browser to not respond to any anchor click, but
you can try customize this. However you can access all the links with
the WebBrowser.ControlInterFace.Document.Links reference. The
WebBrowser.ControlInterFace.Document is an IDispatch interface and all
the DOM interfaces can be accessed thru it. The
WebBrowser.ControlInterFace.Document is referencing the currently loaded
document. So you can populate your listbox with all the links in the
following manner:

Var I:Integer;
     Links:Variant;
Begin
   Links:=WebBrowser.ControlInterFace.Document.Links;
   For I:=0 to Links.length-1 do
     Begin
       ListBox.Items.Add(Links.item(I).innerText);
     End;
End;

Regards:Alex



Relevant Pages

  • Re: TWebBrowser questions
    ... > Property OnMouseMove; ... > the WebBrowser.ControlInterFace.Document.Links reference. ... > WebBrowser.ControlInterFace.Document is an IDispatch interface and all ...
    (borland.public.delphi.thirdpartytools.general)
  • Re: About generics and Iterator
    ... interface. ... The following declarations should be 'equivalent', I mean, all the ... reference, which is incompatible with Iterator, ... Iterator it = v.iterator; ...
    (comp.lang.java.programmer)
  • About generics and Iterator
    ... I have a doubt about generics usage with the iterator ... interface. ... The following declarations should be 'equivalent', I mean, all the ... reference, which is incompatible with Iterator, ...
    (comp.lang.java.programmer)
  • Re: Looking for a Edit box with the text highlight when mouse click first time?
    ... {Protected declarations} ... property ParentBiDiMode; ... property OnMouseDown; ...
    (borland.public.delphi.thirdpartytools.general)
  • Re: variable declaration
    ... looking for the "use strict" equivalent that I was absolutely certain ... It's practically the only thing I've ever expected to find in Python ... paragraph early in the Nutshell book saying "there are no declarations, ... declaration that modifies the reference and not the referent. ...
    (comp.lang.python)