2012-02-13 16 views
3

カスタムコンポーネントTCustomHTTPReqRespを継承して、THTTPReqRespを作成しました。カスタムコンポーネントのイベントが割り当てられていません

このコンポーネントのカスタムイベントも作成しました。私が抱えている唯一の問題は、イベントが発行されてIDEに表示されますが、イベントハンドラを割り当ててアプリケーションを実行するとイベントハンドラが呼び出されないということです。しかし

Form.Createすなわち上のコードでそれを割り当てた場合:

CustomHTTPReqResp1.OnBeforeGet := CustomHTTPReqResp1BeforeGet; 

それが動作します。それ以外は他のすべてがうまく動作します。

何か問題がありましたか?前もって感謝します。

unit CCustomHTTPReqResp; 

interface 

uses 
    SysUtils, Classes, Dialogs, SOAPHTTPTrans; 

type 
    TCustomHTTPReqResp = class(THTTPReqResp) 
    private 
    { Private declarations } 
    FOnBeforeGet: TNotifyEvent; 
    procedure DoOnBeforeGet; 
    protected 
    { Protected declarations } 
    procedure SetOnBeforeGet(const AOnBeforeGet: TNotifyEvent); 
    public 
    { Public declarations } 
    constructor Create(Owner: TComponent); override; 
    destructor Destroy; override; 
    procedure Get(Resp: TStream); override; 
    published 
    { Published declarations } 

    { Events } 
    property OnBeforeGet: TNotifyEvent read FOnBeforeGet write SetOnBeforeGet; 
    end; 

procedure Register; 

implementation 

procedure Register; 
begin 
    RegisterComponents('My Components', [TCustomHTTPReqResp]); 
end; 

{ TCustomHTTPReqResp } 

constructor TCustomHTTPReqResp.Create(Owner: TComponent); 
begin 
    inherited Create(Owner); 
    // Code here. 
end; 

destructor TCustomHTTPReqResp.Destroy; 
begin 
    // Code here. 
    inherited; 
end; 

procedure TCustomHTTPReqResp.SetOnBeforeGet(const AOnBeforeGet: TNotifyEvent); 
begin 
    FOnBeforeGet := AOnBeforeGet; 
end; 

procedure TCustomHTTPReqResp.DoOnBeforeGet; 
begin 
    if Assigned(FOnBeforeGet) then 
    begin 
    FOnBeforeGet(Self); 
    end 
    else 
    begin 
    MessageDlg('No Before Post Event Handler found!', mtInformation, mbOKCancel, 0); 
    end; 
end; 

procedure TCustomHTTPReqResp.Get(Resp: TStream); 
begin 
    // Raise OnBeforeGet. 
    DoOnBeforeGet; 
    inherited Get(Resp); 
end; 


end. 
+3

私によく見えます。あなたが投稿したコードに何か間違ったことはありません。 –

+3

コードに問題はありません。イベントは解雇されています(D2009で確実にテストされています)。トピックノートから*** *** - この場合は 'FOnBeforeGet'のためのセッターが必要ないので、' SetOnBeforeGet'を保存して、直接 'property OnBeforeGet:TNotifyEvent read FOnBeforeGet write FOnBeforeGet; – TLama

答えて

0

コメントみんなのおかげで、先端に感謝TLamaを:ここで

は、カスタムコンポーネントのコードです。

私はフォーム上で間違いをしました。私はツールパレットからフォームにカスタムコントロールをドロップし、同じ名前のForm.Createに別のコントロールを作成しましたが、これが原因で問題が発生したと思います。今修正されました。

関連する問題