unit uIdTCPClient;

interface

uses Classes, Rubies;

var
  cIdTCPClient: Tvalue;

function ap_cIdTCPClient: Tvalue;
procedure Init_IdTCPClient;

implementation

uses
  SysUtils, uDefUtils, Pythia, IdTCPClient, IdHandle, uIndy, uIdTCPConnection;

function ap_cIdTCPClient: Tvalue;
begin
  result := cIdTCPClient;
end;

procedure IdTCPClient_setup(obj: Tvalue; real: TIdTCPClient);
begin
  ap_set_child_attr_module(obj);
end;

function IdTCPClient_event_handle(This, name: Tvalue): Tvalue; cdecl;
begin
  EventHandle(This, name, [Handle, PhiGetHandle]);
  result := Qnil;
end;

function IdTCPClient_connect(This: Tvalue): Tvalue; cdecl;
var
  real: TIdTCPClient;
begin
  real := ap_data_get_struct(This);
  try
    real.Connect;
  except
    on E: Exception do
      ap_raise(ap_eIdSocksError, E.message);
  end;
  result := Qnil;
end;

procedure Init_IdTCPClient;
begin
  cIdTCPClient := rb_define_class_under(mIndy, 'IdTCPClient', cIdTCPConnection);
  DefineProp(cIdTCPClient, TIdTCPClient);
  rb_define_method(cIdTCPClient, 'event_handle', @IdTCPClient_event_handle, 1);
  rb_define_method(cIdTCPClient, 'connect', @IdTCPClient_connect, 0);
end;

end.
