Recent

Author Topic: IdTCPServer Event  (Read 6543 times)

ysun80

  • Newbie
  • Posts: 5
IdTCPServer Event
« on: July 05, 2011, 09:20:04 pm »
I'd like to use IdTCPServer in a console application.
I am not sure if I am right to handle the event (OnExecute), here is my test code,
I always get error on

IdTCPServer1.OnException:=IdTCPServer1Execute(AContext);

Aneone can help me?
Thank you very much,

ysun80

------------------------------------------------------------------
program console_event;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes, SysUtils, CustApp,
  { you can add units after this }
  IdTCPServer, IdContext;
type

  { TMyApplication }

  TMyApplication = class(TCustomApplication)
  protected
    procedure DoRun; override;
  private
    procedure IdTCPServer1Execute(AContext: TIdContext);
  public
  end;

{ TMyApplication }

procedure TMyApplication.IdTCPServer1Execute(AContext: TIdContext);
begin
  Writeln('Event Here');
end;

procedure TMyApplication.DoRun;
var
  ErrorMsg: string;
  IdTCPServer1: TIdTCPServer;
  AContext: TIdContext;
//  AConnection: TIdTCPConnection;
begin

  { add your program here }
  IdTCPServer1.Create;

  AContext := TIdContext.Create(AConnection, AYarn);
  IdTCPServer1.OnException:=IdTCPServer1Execute(AContext);
//  IdTCPServer1.On
  Writeln('Hello Console Event !!!');
  Readln;
  // stop program loop
  IdTCPServer1.Free;
  Terminate;
end;

var
  Application: TMyApplication;

{$R *.res}

begin
  Application:=TMyApplication.Create(nil);
  Application.Run;
  Application.Free;
end.

 

TinyPortal © 2005-2018