Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 29th, 2012  |  syntax: None  |  size: 1.58 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Delphi 2009 not assigning events of custom components
  2. CustomHTTPReqResp1.OnBeforeGet := CustomHTTPReqResp1BeforeGet;
  3.        
  4. unit CCustomHTTPReqResp;
  5.  
  6. interface
  7.  
  8. uses
  9.   SysUtils, Classes, Dialogs, SOAPHTTPTrans;
  10.  
  11. type
  12.   TCustomHTTPReqResp = class(THTTPReqResp)
  13.   private
  14.     { Private declarations }
  15.     FOnBeforeGet: TNotifyEvent;
  16.     procedure DoOnBeforeGet;
  17.   protected
  18.     { Protected declarations }
  19.     procedure SetOnBeforeGet(const AOnBeforeGet: TNotifyEvent);
  20.   public
  21.     { Public declarations }
  22.     constructor Create(Owner: TComponent); override;
  23.     destructor Destroy; override;
  24.     procedure Get(Resp: TStream); override;
  25.   published
  26.     { Published declarations }
  27.  
  28.     { Events }
  29.     property OnBeforeGet: TNotifyEvent read FOnBeforeGet write SetOnBeforeGet;
  30.   end;
  31.  
  32. procedure Register;
  33.  
  34. implementation
  35.  
  36. procedure Register;
  37. begin
  38.   RegisterComponents('My Components', [TCustomHTTPReqResp]);
  39. end;
  40.  
  41. { TCustomHTTPReqResp }
  42.  
  43. constructor TCustomHTTPReqResp.Create(Owner: TComponent);
  44. begin
  45.   inherited Create(Owner);
  46.   // Code here.
  47. end;
  48.  
  49. destructor TCustomHTTPReqResp.Destroy;
  50. begin
  51.   // Code here.
  52.   inherited;
  53. end;
  54.  
  55. procedure TCustomHTTPReqResp.SetOnBeforeGet(const AOnBeforeGet: TNotifyEvent);
  56. begin
  57.   FOnBeforeGet := AOnBeforeGet;
  58. end;
  59.  
  60. procedure TCustomHTTPReqResp.DoOnBeforeGet;
  61. begin
  62.   if Assigned(FOnBeforeGet) then
  63.   begin
  64.     FOnBeforeGet(Self);
  65.   end
  66.   else
  67.   begin
  68.     MessageDlg('No Before Post Event Handler found!', mtInformation, mbOKCancel, 0);
  69.   end;
  70. end;
  71.  
  72. procedure TCustomHTTPReqResp.Get(Resp: TStream);
  73. begin
  74.   // Raise OnBeforeGet.
  75.   DoOnBeforeGet;
  76.   inherited Get(Resp);
  77. end;
  78.  
  79.  
  80. end.