Solved

delphi override Twebbrowser

Posted on 2010-11-19
4
932 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 32

Expert Comment

by:Ephraim Wangoya
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:
Ephraim Wangoya 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:Ephraim Wangoya
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month11 days, 9 hours left to enroll

623 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