Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

delphi override Twebbrowser

Posted on 2010-11-19
4
Medium Priority
?
943 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 2000 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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

704 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