2010-11-19 44 views
2

我試圖做一個cutomized webbrowser這實際上是一個Twebbrowser有一個額外的功能:當頁面沒有在30秒內加載時,它派遣一個事件TimerOut。delphi覆蓋webbrowserH

所以我在TwebbrowsersTimerOut中添加了一個從Twebbrowser繼承的計時器。

這個想法是在BeforeNavigate或DownloadBegin事件中吃飯這個計時器:並停止onDownloadComplete事件的計數器。

麻煩的是,我不知道如何來覆蓋這些事件:,更在全球範圍如何覆蓋從現有組件的事件:有人可以幫助我的首要TwebBrowser組件和especailly它的事件?

問候

回答

1

一般情況下,事件是可以在自定義後裔設置只是正常的屬性。你可以基本上攔截事件並提供你自己的控制器。

比如,我剛剛創建了覆蓋的的OnExit事件組件...

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;