Sign in Join

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

Mailing lists / fpc-pascal / 2009-05

Class procedure assigned to object's event

6 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

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

Unknown author

Hi all,

I'm working on a code I have found on internet about a little ftp client using synapse. This code:

class procedure callback.StatusCMD(Sender: TObject; Response: Boolean;
 const Value: string);

defines a class procedure that in delphi mode assigned to:

if cbOnStatusCMD.Checked then
   FTP.OnStatus:=callback.StatusCMD
 else
   FTP.OnStatus:=nil;

compile fine.
But if I set {$mode objfpc} rather than delphi I got:

main.pas(262,3) Error: Wrong number of parameters specified for call to "StatusCMD"

I think because synapse source has delphi mode on.

The following is the type of OnStatus event:

TFTPStatus = procedure(Sender: TObject; Response: Boolean;
   const Value: string) of object;
 
Is there a way to compile with objfpc or better which is the difference between two modes for this case ?

Thanks
Antonio

Antonio Sanguigni alias slapshot ---------------------------------------------------------------------- GioveLUG (Linux User Group) - http://www.giovelug.org Edupup (Educational distro) - http://www.pieroni.biz/edupup

Reply by email

Graeme Geldenhuys
to Unknown author

2009/5/26 :

Show quoted text 11 lines
if cbOnStatusCMD.Checked then    FTP.OnStatus:=callback.StatusCMD  else    FTP.OnStatus:=nil; compile fine. But if I set {$mode objfpc} rather than delphi I got: main.pas(262,3) Error: Wrong number of parameters specified for call to "StatusCMD"

You need to assign the address of that method in objfpc mode using the @ syntax.

or was it...

Something like that. I can never remember which. ;-)

Is there a way to compile with objfpc or better which is the difference between two modes for this case ?

I prefer objfpc mode as it's a lot stricter than delphi mode. But if you work on shared code projects that must compile under Delphi and FPC, it is just easier (and cleaner) to use delphi mode. Otherwise you sit with a lot of {$IFDEF FPC} entries.

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Antonio Sanguigni
to Graeme Geldenhuys

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Graeme Geldenhuys wrote
You need to assign the address of that method in objfpc mode using

the @ syntax.

Show quoted text 6 lines
or was it... Something like that. I can never remember which. ;-)
Well I already tried it. For the first one I got:
main.pas(261,28) Fatal: Syntax error, "identifier" expected but "@" found

For the second one:
main.pas(261,19) Error: Incompatible types: got "<class method type of procedure(TObject, Boolean,const AnsiString) of object;Register>" expected "<procedure variable type of procedure(TObject, Boolean,const AnsiString) of object;Register>"

I prefer objfpc mode as it's a lot stricter than delphi mode. But if

Me too ;).

you work on shared code projects that must compile under Delphi and FPC, it is just easier (and cleaner) to use delphi mode. Otherwise you sit with a lot of {$IFDEF FPC} entries.

Oh yes, that's not a problem. Just setting delphi mode is ok for me. I was curios to better understand fpc behaviour.

Thanks
Antonio
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkob+WoACgkQYSsm1R1/E7wBMgCfdXAtfgTvWNFsxPZXbAwjqCSi DPYAoONBGI0Htpnj/+gPkXEX20H3vvYb
=H7dQ
-----END PGP SIGNATURE-----

Reply by email

JoshyFun
to Unknown author: I'm working on a code I have found on internet about a little ftp client using synapse.…

Hello FPC-Pascal,

Tuesday, May 26, 2009, 4:03:00 PM, you wrote:

asgc> class procedure callback.StatusCMD(Sender: TObject; Response: Boolean; asgc>  const Value: string);
[...]
asgc> Is there a way to compile with objfpc or better which is asgc> the difference between two modes for this case ?

I may be wrong, but "class procedure" and "of object" may be incompatible even when the "class procedure" should be the same as a regular "of object" one with an implicit nil passed.

Which FPC version are you using ?

Best regards, JoshyFun

Reply by email

Antonio Sanguigni
to JoshyFun

2009/5/26 JoshyFun :

I may be wrong, but "class procedure" and "of object" may be incompatible even when the "class procedure" should be the same as a regular "of object" one with an implicit nil passed.

Well I really don't know :) but searching on internet for delphi I found this as a simple way to assign procedure of object to object's event methods.

Which FPC version are you using ?

I'm using 2.3.1 but I tried with 2.2.5 too and I have the same thing.

Antonio

Antonio Sanguigni alias slapshot ---------------------------------------------------------------------- GioveLUG (Linux User Group) - http://www.giovelug.org Edupup (Educational distro) - http://www.pieroni.biz/edupup

Reply by email

Micha Nelissen
to Antonio Sanguigni: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 the @ syntax. Well I already tried it. For…
Antonio Sanguigni wrote 5 lines
For the second one: main.pas(261,19) Error: Incompatible types: got "<class method type of procedure(TObject, Boolean,const AnsiString) of object;Register>" expected "<procedure variable type of procedure(TObject, Boolean,const AnsiString) of object;Register>"

Remove the 'class' keyword from your function. A class method is a different beast (with different signature) from a regular method.

Micha

Reply by email