Solved

delphi override Twebbrowser

Posted on 2010-11-19
4
875 Views
Last Modified: 2012-06-27
Hello experts,

I try to make a cutomized webbrowser which infact is a Twebbrowser that has an extra feature: it dispatch an event TimerOut when the page does not load within 30 seconds.

SO I added an timer in TwebbrowsersTimerOut that inherits from Twebbrowser.

The idea would be to lunch this timer on the BeforeNavigate or DownloadBegin event:  and stop the counter on the onDownloadComplete event.

**Trouble is that I have no idea how to override these events:**  and more globally how to override events from existing components: can someone help me with overriding TwebBrowser components and especailly its events ?


Thanks
0
Comment
Question by:yarekGmail
  • 3
4 Comments
 
LVL 32

Expert Comment

by:ewangoya
ID: 34177860

There are really no methods to override in the TWebBrowser component. You could just add a timer to your form and when the downloadbegin is triggered start your timer and stop it when DownLoadComplete event is triggered

However, if you want to extend, TWebBrowser, you can add your own events to mirror the existing events then hide the existing events. Here is an example with BeginDownload and Downloacomplete events
uses

  Windows, SysUtils, Classes, OleCtrls, SHDocVw, ExtCtrls;



type

  TCustomWebBrowser = class(TWebBrowser)

  private

    FOnCustomDownloadBegin: TNotifyEvent;

    FOnCustomDownloadComplete: TNotifyEvent;

    FTimer: TTimer;

    procedure DoDownLoadComplete(Sender: TObject);

    procedure DoDownLoadBegin(Sender: TObject);

    procedure DoTimerEvent(Sender: TObject);

    function GetTimeout: Cardinal;

    procedure SetTimeout(const Value: Cardinal);

  protected

    property OnDownloadBegin;

    property OnDownloadComplete;

  public

    constructor Create(AOwner: TComponent); override;

    destructor Destroy; override;

  published

    property Timeout: Cardinal read GetTimeout write SetTimeout;

    property OnCustomDownloadBegin: TNotifyEvent read FOnCustomDownloadBegin write FOnCustomDownloadBegin;

    property OnCustomDownloadComplete: TNotifyEvent read FOnCustomDownloadComplete write FOnCustomDownloadComplete;

  end;





implementation





{ TCustomWebBrowser }



constructor TCustomWebBrowser.Create(AOwner: TComponent);

begin

  inherited Create(AOwner);

  FTimer := TTimer.Create(nil);

  //set the events

  OnDownloadBegin := DoDownloadBegin;

  OnDownloadComplete := DoDownLoadComplete;

end;



destructor TCustomWebBrowser.Destroy;

begin

  FTimer.Enabled := False;

  FreeAndNil(FTimer);

  inherited Destroy;

end;



procedure TCustomWebBrowser.DoDownLoadBegin(Sender: TObject);

begin

  if Assigned(FOnCustomDownLoadBegin) then

    FOnCustomDownLoadBegin(Self);

  FTimer.Enabled := True;

end;



procedure TCustomWebBrowser.DoDownLoadComplete(Sender: TObject);

begin

  FTimer.Enabled := False;

  if Assigned(FOnCustomDownloadComplete) then

    FOnCustomDownloadComplete(Self)

end;



procedure TCustomWebBrowser.DoTimerEvent(Sender: TObject);

begin

  //add what you want to do here

end;



function TCustomWebBrowser.GetTimeout: Cardinal;

begin

  Result := FTimer.Interval;

end;



procedure TCustomWebBrowser.SetTimeout(const Value: Cardinal);

begin

  FTimer.Interval := Value

end;



end;

Open in new window

0
 
LVL 32

Accepted Solution

by:
ewangoya earned 500 total points
ID: 34177869
You have to set the ontimer event on create

uses
  Windows, SysUtils, Classes, OleCtrls, SHDocVw, ExtCtrls;

type
  TCustomWebBrowser = class(TWebBrowser)
  private
    FOnCustomDownloadBegin: TNotifyEvent;
    FOnCustomDownloadComplete: TNotifyEvent;
    FTimer: TTimer;
    procedure DoDownLoadComplete(Sender: TObject);
    procedure DoDownLoadBegin(Sender: TObject);
    procedure DoTimerEvent(Sender: TObject);
    function GetTimeout: Cardinal;
    procedure SetTimeout(const Value: Cardinal);
  protected
    property OnDownloadBegin;
    property OnDownloadComplete;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    property Timeout: Cardinal read GetTimeout write SetTimeout;
    property OnCustomDownloadBegin: TNotifyEvent read FOnCustomDownloadBegin write FOnCustomDownloadBegin;
    property OnCustomDownloadComplete: TNotifyEvent read FOnCustomDownloadComplete write FOnCustomDownloadComplete;
  end;


implementation


{ TCustomWebBrowser }

constructor TCustomWebBrowser.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FTimer := TTimer.Create(nil);
  FTimer.OnTimer := DoTimerEvent;
  //set the events
  OnDownloadBegin := DoDownloadBegin;
  OnDownloadComplete := DoDownLoadComplete;
end;

destructor TCustomWebBrowser.Destroy;
begin
  FTimer.Enabled := False;
  FreeAndNil(FTimer);
  inherited Destroy;
end;

procedure TCustomWebBrowser.DoDownLoadBegin(Sender: TObject);
begin
  if Assigned(FOnCustomDownLoadBegin) then
    FOnCustomDownLoadBegin(Self);
  FTimer.Enabled := True;
end;

procedure TCustomWebBrowser.DoDownLoadComplete(Sender: TObject);
begin
  FTimer.Enabled := False;
  if Assigned(FOnCustomDownloadComplete) then
    FOnCustomDownloadComplete(Self)
end;

procedure TCustomWebBrowser.DoTimerEvent(Sender: TObject);
begin
  //add what you want to do here
end;

function TCustomWebBrowser.GetTimeout: Cardinal;
begin
  Result := FTimer.Interval;
end;

procedure TCustomWebBrowser.SetTimeout(const Value: Cardinal);
begin
  FTimer.Interval := Value
end;

end;
0
 

Author Comment

by:yarekGmail
ID: 34179333
This is Great but I have ONE QUETSION:
You added some EXTRA events: like OnCustomDownloadBegin, OnCustomDownloadComplete

Is it possible to override the existing one without having to create new ones ?

regards
0
 
LVL 32

Expert Comment

by:ewangoya
ID: 34180387

Not incase of the TWebBrowser, you can only override methods, not events. Since TWebBrowser is a direct descendant of TOleControl, there are no methods of TWebBrowser that can be overriden. You can only create extra methods and events
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now