Sign in Join

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

Mailing lists / fpc-pascal / 2006-02

Delphi mode

3 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

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

Carsten Bager

Why do I have to use the {$MODE Delphi} directive to compile this, It compiles in TP 6

-------------
Type
  tFun=function:boolean;
Procedure g(f:tFun);
Begin
 if f then exit;
End;
------------------
I ask because when I am in Delphi mode this can not compile
Var
  tekster:Tekster_typ; external name 'tekster';

Free Pascal Compiler version 2.0.2 [2005/12/16] for arm Copyright (c) 1993-2005 by Florian Klaempfl
Target OS: Linux for ARM
Compiling led.pas
Compiling Menu.pas
Menu.pas(41,5) Error: Boolean expression expected, but got "<procedure variable type of function:Boolean;StdCall>"

Regards

Carsten

Jonas Maebe
to Carsten Bager
Carsten Bager wrote
Why do I have to use the {$MODE Delphi} directive to compile this, It compiles in TP 6

You can also use {$mode tp} (and you should if you are compiling TP code).

Show quoted text 9 lines
------------- Type tFun=function:boolean; Procedure g(f:tFun); Begin if f then exit; End; ------------------

You have to use "if f() then exit;" in FPC (the default) and OBJFPC mode.

Jonas

Vincent Snijders
to Carsten Bager: Why do I have to use the {$MODE Delphi} directive to compile this, It compiles in TP 6…
Carsten Bager wrote 13 lines
Why do I have to use the {$MODE Delphi} directive to compile this, It compiles in TP 6 ------------- Type tFun=function:boolean; Procedure g(f:tFun); Begin if f then exit; End; ------------------

Because f is a function variable and not the result. In Delphi it can mean two things (and I wonder what happens if the result of a function is a tFun :-)).

If you want to call f, use this:
if f() then exit;

Vincent.