tblock3a.pp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. { %target=darwin,iphonesim}
  2. { %skipcpu=powerpc,powerpc64 }
  3. program tblock3a;
  4. {$mode objfpc}
  5. {$modeswitch cblocks}
  6. type
  7. {$calling cdecl}
  8. tblock1 = reference to procedure(j: longint); cblock;
  9. {$calling mwpascal}
  10. tblock2 = reference to procedure(j : longint); cblock;
  11. tc = class
  12. i: longint;
  13. procedure callme(j: longint);
  14. end;
  15. var
  16. b1: tblock1;
  17. b2: tblock2;
  18. c: tc;
  19. procedure tc.callme(j: longint);
  20. const
  21. invocationcount: longint = 0;
  22. begin
  23. writeln('self: ',hexstr(pointer(self)),', i: ',i,', j: ',j);
  24. if self<>c then
  25. halt(1);
  26. if i<>12345 then
  27. halt(2);
  28. case invocationcount of
  29. 0:
  30. if j<>1 then
  31. halt(3);
  32. 1, 2:
  33. if j<>2 then
  34. halt(4);
  35. 3:
  36. if j<>3 then
  37. halt(5);
  38. 4, 5:
  39. if j<>4 then
  40. halt(6);
  41. end;
  42. inc(invocationcount);
  43. end;
  44. procedure test1(b: tblock1);
  45. begin
  46. b1(2);
  47. end;
  48. procedure test2(b: tblock2);
  49. begin
  50. b2(4);
  51. end;
  52. begin
  53. c:=tc.create;
  54. c.i:=12345;
  55. b1:[email protected];
  56. b1(1);
  57. test1(@c.callme);
  58. test1(b1);
  59. b2:[email protected];
  60. b2(3);
  61. test2(@c.callme);
  62. test2(b2);
  63. end.