[fpc-pascal] Events doesn't work in .lpr ?

Benedikt Schindler BeniSchindler at gmx.de
Fri Dec 11 11:15:55 CET 2009


Hi,

i wrote a short test programm, to find out how to use the lnet unit.
And now i got some strange compiler messages. (FPC 2.2.2 for i386.)

The source Code is very short. So i just atached the hole cource code.
i got 2 compiler messsages and i think they are directly connected.

Here they are:

SCServer.lpr(46,43) Error: Wrong number of parameters specified for call 
to "DoOnReciveCommand"
SCServer.lpr(33,21) Hint: Found declaration: 
TSCServer.DoOnReciveCommand(TLSocket)


Now my question:

Why does it say "Found declaration DoOnReciveCommand"? I mean it is 
declared 4 lines earlier. where is the difference to the procedure DoRun ?

I think the error is result of the hint.

for all who don't know the lnet unit. in this unit there is this event 
declaration :

 > { Callback Event procedure for others }
 > TLSocketEvent = procedure(aSocket: TLSocket) of object;

any ideas, why there is the hint.... or the error?

greatings
Benedikt



[SourceCode SCServer.lpr]


program SCServer;

{$mode objfpc}{$H+}

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


type

   { TSCServer }

   TSCServer = class(TCustomApplication)
   private
     TCPServer : TLTcp;
     TCPPort : integer;
     TCPIp   : string;
   protected
     procedure DoRun; override;
   public
     constructor Create(TheOwner: TComponent); override;
     destructor Destroy; override;
     procedure DoOnReciveCommand(aSocket: TLSocket);
   end;


{ TSCServer }

procedure TSCServer.DoOnReciveCommand(aSocket: TLSocket);
var
   test : string;
begin
   aSocket.GetMessage(test);
   WriteLn(test);
end;

procedure TSCServer.DoRun;
begin
   { add your program here }

   // open TCP Server
   TCPServer.OnReceive := DoOnReciveCommand;
   TCPServer.Listen(TCPPort,TCPIp);
   // Der TCP Server ist Event gesteuert.
   // wir können uns deswegen nun komplett auf die
   // höhensteuerung konzentrieren.


   // stop program loop
   Terminate;
end;

constructor TSCServer.Create(TheOwner: TComponent);
begin
   inherited Create(TheOwner);
   TCPServer := TLTcp.Create(nil);
   TCPPort := 23;
   TCPIp := LADDR_ANY;
end;

destructor TSCServer.Destroy;
begin

   TCPServer.Free;
   inherited Destroy;
end;


var
   Application: TSCServer;
begin
   Application:=TSCServer.Create(nil);
   Application.Title:='SCServer';
   Application.Run;
   Application.Free;
end.



More information about the fpc-pascal mailing list