* * *

Author Topic: class procedure  (Read 1111 times)

aliotti

  • New member
  • *
  • Posts: 17
class procedure
« on: June 18, 2012, 08:59:48 pm »
 I have the code down:

     TXYZ = class ...
                    public
                        class procedure ax(a,b,c:string);
                    end;

   and in another file do:
  type
      TprocX = procedure ay(a,b,c:string) of object;


  .... and more down

onAbc:TprocX;


onAbc := @TXYZ.ax(a,b,c:string);

When It is compiled return message :

<filename>.pas(X,Y) Error: Incompatible types: got "<class method type of procedure(a,b,c:string) of object;Register>" expected "<procedure variable type of procedure(a,b,c:string) of object;Register>"

any idea how correct it.

howardpc

  • Full Member
  • ***
  • Posts: 220
Re: class procedure
« Reply #1 on: June 18, 2012, 11:17:04 pm »
You've declared TprocX (and thus onABC) as a method variable, not as a class method variable, so it is not assignment compatible with a class method address.
If you create an instance of TXYZ
var aXYZ: TXYZ;
aXYZ := TXYZ.Create;
then onABC will be assignment compatible with the 'normal' method address, @aXYZ.ax(...)

User137

  • Hero Member
  • *****
  • Posts: 1040
Re: class procedure
« Reply #2 on: June 20, 2012, 02:59:43 pm »
Quote
onAbc := @TXYZ.ax(a,b,c:string);
Assignment doesn't look right. This?
Code: [Select]
onAbc := @TXYZ.ax;

circular

  • Hero Member
  • *****
  • Posts: 1401
    • Personal webpage
Re: class procedure
« Reply #3 on: June 20, 2012, 07:02:14 pm »
What about :
Code: [Select]
TprocX = class procedure ay(a,b,c:string) of object;
Conscience is the debugger of the mind

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads