Delphi mode

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Delphi mode

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
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Delphi mode

Jonas Maebe-2

On 2 feb 2006, at 16:10, 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).

> -------------
> 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

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Delphi mode

Vincent Snijders
In reply to this post by Carsten Bager
Carsten Bager wrote:

> 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.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal