开发者

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

开发者 https://www.devze.com 2023-04-13 05:00 出处:网络
I don\'t understand why the following small console application does not compile: program Project1; type

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 := procedu开发者_JS百科re begin writeln; end;
  myProc; // compiles fine
  myRec.Proc := procedure begin writeln; end;
  myRec.Proc; //E2014 Statement exptected, but expression of type 'TProc' found
end.


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

myRec.Proc();
0

精彩评论

暂无评论...
验证码 换一张
取 消