tblock2.pp 761 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. { %target=darwin,iphonesim}
  2. { %skipcpu=powerpc,powerpc64 }
  3. {$mode objfpc}
  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. 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:[email protected];
  40. b(1);
  41. test(@c.callme);
  42. test(b);
  43. end.