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

2009-12-11 Thread 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.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


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

2009-12-11 Thread Jonas Maebe

On 11 Dec 2009, at 11:15, Benedikt Schindler wrote:


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 
___

fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


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

2009-12-11 Thread Benedikt Schindler




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
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Make Pascal library usable for C (on Linux)

2009-12-11 Thread Jonas Maebe


On 10 Dec 2009, at 20:27, Matthias Klumpp wrote:


I write C-headers for a library written in Pascal at time, to make it
usable within C applications.
On Linux, the libtool-program (part of GNU autotools) generates the
necessary files for C-compilers to link against the library  
(libxyz.la,

libxyz.a, libxyz.pc)
How can I use libtool for Pascal libraries or is there an  
alternative way

to get the libtool-comfort with Pascal?


I think you better ask that on a libtool mailing list. I have no idea  
what libtool requires from a compiler, how it determines what to put  
in those .la and .pc files, etc. There is no explicit libtool support  
in FPC, and I've never seen any patches that add it.



Jonas
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Make Pascal library usable for C (on Linux)

2009-12-11 Thread Matthias Klumpp
On Fri, 11 Dec 2009 15:48:49 +0100, Jonas Maebe 
wrote:
> I think you better ask that on a libtool mailing list. I have no idea  
> what libtool requires from a compiler, how it determines what to put  
> in those .la and .pc files, etc. There is no explicit libtool support  
> in FPC, and I've never seen any patches that add it.
Okay, then I'll try to write the files by myself.
Has someone experience in using Pascal libraries with C on Linux?
I will just write some code now and try if it works.
Thanks!
 Matthias Klumpp

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] Class Operators

2009-12-11 Thread Andreas Schneider
Hi,

since my reported "bug" (http://bugs.freepascal.org/view.php?id=15315) seems 
to turn out to be "by design", a question came up:
are there any plans to implement class operators? In delphi they are 
implemented to allow operators to affect instances of classes. This would also 
enable to write operator overloads that work with generics. A good example of 
that would be smartpointers. A small snippet from an example in delphi:

  TSmartPointer = record
  strict private
FValue: T;
FLifetime: IInterface;
  public
constructor Create(const AValue: T); overload;
class operator Implicit(const AValue: T): TSmartPointer;
property Value: T read FValue;
  end;

There are surely other cases where class operators would fit in nice. They 
could for example allow to build something like TPersistent.Assign as := 
operator.

Is this already on a todo-list or am I out of luck here?

Thanks,
Andreas.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal