How can I initialize my custom IdIOHandler fields?

Viewed 115

This is blowing my mind... I just want to make a new IdIOHandler, and, as usual, I need to do some initialization in the constructor... Normally, I override the constructor of the base class, but this TIdIOHandlerStack which I inherit from, is far from "normal" ! It has no constructor to override, and is not known (to me) how it is created.

  TIdEnhancedIOHandler = class(TIdIOHandlerStack)
  private
    FSendBuffer: TIdBytes;
    FSendBuff: TDataStream;
  public
    constructor Create;  // <-- I tested all the variations here, but non of them work
    destructor  Destroy; override;
  end;

  implementation

  constructor TIdEnhancedIOHandler.Create;
  begin
   inherited Create;
   FSendBuff:= TDataStream.Create(@SendBuffer);
  end;

  destructor TIdEnhancedIOHandler.Destroy;
  begin
   FSendBuff.Free;
   inherited;
  end;

  initialization

    TIdEnhancedIOHandler.SetDefaultClass;

Where should I put my intitialization code so that it is executed when a new instance of TIdEnhancedIOHandler is created BY DEFAULT in all Indy Components which use IOHandlers ?

1 Answers

I found it... It was the InitComponent method that I must override.

  TIdEnhancedIOHandler = class(TIdIOHandlerStack)
  private
    FSendBuffer: TIdBytes;
    FSendBuff: TDataStream;
  public
    procedure   InitComponent; override;
    destructor  Destroy; override;
  end;

  implementation

procedure TIdEnhancedIOHandler.InitComponent;
begin
 inherited;
 FSendBuff:= TDataStream.Create(@SendBuffer);
end;
Related