Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Delphi, unable to use anonymus type as a type of a record?

I don't understand why the following small console application does not compile:

program Project1;

type
  TProc = reference to procedure;

  TMyRec = record
    Proc: TProc;
  end;

var
  myProc: TProc;
  myRec: TMyRec;

begin
  myProc := procedure begin writeln; end;
  myProc; // compiles fine
  myRec.Proc := procedure begin writeln; end;
  myRec.Proc; //E2014 Statement exptected, but expression of type 'TProc' found
end.
like image 466
RM. Avatar asked Oct 16 '11 23:10

RM.


1 Answers

You must add parenthesis to indicate that you're calling the procedure; i.e.,

myRec.Proc();
like image 156
ain Avatar answered Sep 28 '22 03:09

ain