Question

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 ?

regards

Was it helpful?

Solution

In general, events are just normal properties which can be set in your custom descendant. You can basically intercept the event and provide your own controller.

For example, I just created a Component that overrode the OnExit event...

interface

TmyWhatever = class(TWhateverAncestor)
private
  fMyOnExit:TNotifyEvent
protected
  procedure CustomOnExitEvent(Sender:TObject);
public
  constructor Create(AOwner:TComponent); override;
published
  //we provide our own OnExit event (to be set by the developer using this component)
  property OnExit:TNotifyEvent read fMyOnExit write fMyOnExit
end;

implementation

constructor TmyWhatever.Create(AOwner:TComponent);
begin
  inherited;

  //setup our event in the parent
  inherited OnExit := CustomOnExitEvent;
end;

procedure TmyWhatever.CustomOnExitEvent(Sender:TObject);
begin
  //perhaps do custom work before the OnExit

  //and then call the intercepted OnExit event, if needed
  if Assigned(fMyOnExit) then
  begin
    fMyOnExit(Sender);
  end;

  //perhaps do custom work after the OnExit 
end;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top