tblock2a.pp 796 B

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