fpc/tests/test/tblock2a.pp
Jonas Maebe 2bc8afaa63 + support for calling a method via a block: we capture the method as a
procvar in the local state of the block, and then call it insde the
    generated invoke routine. We can't call it directly there, because
    due to visibility reasons it may not be accessible from a regular
    procedure (e.g. if it is a strict private method)

git-svn-id: branches/blocks@28234 -
2014-07-18 09:15:35 +00:00

52 lines
756 B
ObjectPascal

{ %target=darwin,iphonesim}
{$mode delphi}
{$modeswitch blocks}
type
tblock = reference to procedure(j: longint); cdecl;
tc = class
i: longint;
procedure callme(j: longint);
end;
var
b: tblock;
p: procedure(j: longint) of object;
c: tc;
procedure tc.callme(j: longint);
const
invocationcount: longint = 0;
begin
writeln('self: ',hexstr(pointer(self)),', i: ',i,', j: ',j);
if self<>c then
halt(1);
if i<>12345 then
halt(2);
if invocationcount=0 then
begin
if j<>1 then
halt(3)
end
else if j<>2 then
halt(4);
inc(invocationcount);
end;
procedure test(b: tblock);
begin
b(2);
end;
begin
c:=tc.create;
c.i:=12345;
b:=c.callme;
b(1);
test(c.callme);
test(b);
end.