Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2009-12

Events doesn't work in .lpr ?

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Benedikt Schindler

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.
Jonas Maebe
to Benedikt Schindler
Benedikt Schindler wrote 14 lines
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"?

It says this because you are trying to call DoOnReciveCommand without any parameters. The compiler is trying to help you by saying that it only knows of a method with that name that has one parameter.

I mean it is declared 4 lines earlier. where is the difference to the procedure DoRun ?

The problem is that you are using Delphi/TP-style procvar syntax in source code compiled {$mode objfpc}. Either add @ in front of DoOnReciveCommand when assigning it to DoRun, or change {$mode objfpc} into {$mode delphi}.

Jonsa

Benedikt Schindler
to Jonas Maebe
Show quoted text 10 lines
> I mean it is declared 4 lines earlier. where is the difference to the > procedure DoRun ? The problem is that you are using Delphi/TP-style procvar syntax in source code compiled {$mode objfpc}. Either add @ in front of DoOnReciveCommand when assigning it to DoRun, or change {$mode objfpc} into {$mode delphi}.

thx.

i thought of a problem like that, and changed my compiler default to "delphi".
But i forget that there is a compiler directive in line 2 that just switched it back to "objfpc".

thx again
Benedikt