Sign in Join

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

Mailing lists / fpc-pascal / 2002-10

How to call a variable of a procedural type?

3 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

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

mili

Hello, every body

I write codes as the following:

>>>>>>>
type TFunc = function : integer;
function myfunction:integer;
begin
  Result:=100;
end;//myfunction:
var
  fun : TFunc;
  a   : integer;
begin
  fun:=TFunc;
  a:=fun;
  writeln(fun);
end.

<<<<<<<<

When I compile it, compiler report that at line of "@1" there's an error. But when I comment the line of "@1", the line of "@2" can work well.

I don't know how to return the value of a procedural function variable. Can anybody tell me that? And tell me what's the different of lines between "@1" and "@2".

Thank you,
yours,
mili

Peter Vreman
to mili
you wrote 31 lines
Hello, every body I write codes as the following: >>>>>>>> type TFunc = function : integer; function myfunction:integer; begin Result:=100; end;//myfunction: var fun : TFunc; a : integer; begin fun:=TFunc; a:=fun; writeln(fun); end. <<<<<<<< When I compile it, compiler report that at line of "@1" there's an error. But when I comment the line of "@1", the line of "@2" can work well. I don't know how to return the value of a procedural function variable. Can anybody tell me that? And tell me what's the different of lines between "@1" and "@2".

the writeln(fun) calls function fun() and writes the result of the function.

you should use the following code:

;
writeln(longint(@fun));

Peter

Pedro Lopez-Cabanillas
to mili: Hello, every body I write codes as the following: type TFunc = function : integer;…

Hi,

There are two different syntax available:

{$mode FPC}
begin
  ;
  a:=fun();
  writeln(fun);
end.
{$mode TP}
begin
  fun:=myfunction;
  a:=fun;
  writeln(fun);
end.

You can see that the assignement instruction is different in FPC (native mode) and TP compatibility mode. In @1 there is another difference, because some ambiguity that is not at @2.

Online docs explainig this:
http://www.freepascal.org/docs-html/prog/node18.html#SECTION001810000000000000000 http://www.freepascal.org/docs-html/ref/node6.html#SECTION03350000000000000000

Regards,
Pedro

ALSAPAS: ALSA Library bindings for Pascal http://alsapas.alturl.com