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.
私によく見えます。あなたが投稿したコードに何か間違ったことはありません。 –
コードに問題はありません。イベントは解雇されています(D2009で確実にテストされています)。トピックノートから*** *** - この場合は 'FOnBeforeGet'のためのセッターが必要ないので、' SetOnBeforeGet'を保存して、直接 'property OnBeforeGet:TNotifyEvent read FOnBeforeGet write FOnBeforeGet; – TLama