Sign in Join

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

Mailing lists / fpc-devel / 2015-10

Assign static class procedure to procedure variable

6 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

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

Ondrej Pokorny

Hello!

In Delphi it is valid to assign a static class procedure to a procedure variable:

program project1;
type
   TMyObject = class
   public
     class procedure Proc; static;
   end;
   TProc = procedure();
class procedure TMyObject.Proc;
begin
end;
var
   xProc: TProc;
begin
*  xProc := @TMyObject.Proc;**
*end.

(In Delphi just without the @ operator, obviously.)

In FPC 3.1.1 (trunk) I get the following error:

project1.lpr(22,12) Error: Incompatible types: got "<class method type of procedure of object;Register>" expected "<procedure variable type of procedure;Register>"

Why? Can it be achieved somehow (compiler settings)?

Ondrej

Reply by email

Maciej Izak
to Ondrej Pokorny

Just use Delphi mode. :)
17.10.2015 09:01 "Ondrej Pokorny" napisał(a):

Show quoted text 43 lines
Hello! In Delphi it is valid to assign a static class procedure to a procedure variable: program project1; type TMyObject = class public class procedure Proc; static; end; TProc = procedure(); class procedure TMyObject.Proc; begin end; var xProc: TProc; begin * xProc := @TMyObject.Proc;* end. (In Delphi just without the @ operator, obviously.) In FPC 3.1.1 (trunk) I get the following error: project1.lpr(22,12) Error: Incompatible types: got "<class method type of procedure of object;Register>" expected "<procedure variable type of procedure;Register>" Why? Can it be achieved somehow (compiler settings)? Ondrej _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply by email

Jonas Maebe
to Ondrej Pokorny
Ondrej Pokorny wrote
Ok, that is possible. No chance to get it working in objfpc mode?

It's a known bug since quite a long time, but nobody got around to fixing it yet. There's a report for it on the bug tracker.

Jonas

Reply by email

Ondrej Pokorny
to Jonas Maebe: It's a known bug since quite a long time, but nobody got around to fixing it yet. There's…
Jonas Maebe wrote 5 lines
On 17/10/15 10:14, Ondrej Pokorny wrote: > Ok, that is possible. No chance to get it working in objfpc mode? It's a known bug since quite a long time, but nobody got around to fixing it yet. There's a report for it on the bug tracker.

Thanks for committing the patch. There is room for a small optimization
- you don't have to check "po_staticmethod" afterwards. The check is already done in "{ b) }". See attached patch. (I cannot attach files to resolved issue reports, therefore I send it here.)

Ondrej

Reply by email