tblock2a.pp 756 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. { %target=darwin,iphonesim}
  2. {$mode delphi}
  3. {$modeswitch blocks}
  4. type
  5. tblock = reference to procedure(j: longint); cdecl;
  6. tc = class
  7. i: longint;
  8. procedure callme(j: longint);
  9. end;
  10. var
  11. b: tblock;
  12. p: procedure(j: longint) of object;
  13. c: tc;
  14. procedure tc.callme(j: longint);
  15. const
  16. invocationcount: longint = 0;
  17. begin
  18. writeln('self: ',hexstr(pointer(self)),', i: ',i,', j: ',j);
  19. if self<>c then
  20. halt(1);
  21. if i<>12345 then
  22. halt(2);
  23. if invocationcount=0 then
  24. begin
  25. if j<>1 then
  26. halt(3)
  27. end
  28. else if j<>2 then
  29. halt(4);
  30. inc(invocationcount);
  31. end;
  32. procedure test(b: tblock);
  33. begin
  34. b(2);
  35. end;
  36. begin
  37. c:=tc.create;
  38. c.i:=12345;
  39. b:=c.callme;
  40. b(1);
  41. test(c.callme);
  42. test(b);
  43. end.