tpvardelphi.pp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. program tpvardelphi;
  2. {$mode delphi}
  3. uses
  4. jdk15;
  5. type
  6. tmprec = record
  7. b: byte;
  8. end;
  9. tmethodclass = class
  10. l: longint;
  11. procedure test(x: longint; w: word; r: tmprec; var ro: tmprec);
  12. procedure shorttest(b: byte);
  13. procedure shorttest2(b: byte);
  14. end;
  15. tmypvar = procedure(x: longint; w: word; r: tmprec; var ro: tmprec) of object;
  16. tmyshortpvar = procedure(b: byte) of object;
  17. procedure tmethodclass.test(x: longint; w: word; r: tmprec; var ro: tmprec);
  18. begin
  19. jlsystem.fout.print('l: ');
  20. jlsystem.fout.println(l);
  21. jlsystem.fout.print('x: ');
  22. jlsystem.fout.println(x);
  23. jlsystem.fout.print('w: ');
  24. jlsystem.fout.println(w);
  25. jlsystem.fout.print('r.b: ');
  26. jlsystem.fout.println(r.b);
  27. jlsystem.fout.print('ro.b: ');
  28. jlsystem.fout.println(ro.b);
  29. if l<>6 then
  30. raise jlexception.create('l wrong on input');
  31. if x<>1 then
  32. raise jlexception.create('x wrong on input');
  33. if w<>$ffff then
  34. raise jlexception.create('w wrong on input');
  35. if r.b<>21 then
  36. raise jlexception.create('r.b wrong on input');
  37. if ro.b<>42 then
  38. raise jlexception.create('ro.b wrong on input');
  39. r.b:=123;
  40. ro.b:=123;
  41. end;
  42. procedure tmethodclass.shorttest(b: byte);
  43. begin
  44. if b<>129 then
  45. raise jlexception.create('shorttest b wrong');
  46. if l<>7 then
  47. raise jlexception.create('shorttest l wrong');
  48. end;
  49. procedure tmethodclass.shorttest2(b: byte);
  50. begin
  51. if b<>130 then
  52. raise jlexception.create('shorttest2 b wrong');
  53. if l<>6 then
  54. raise jlexception.create('shorttest l wrong');
  55. end;
  56. var
  57. mypvar, mypvar2: tmypvar;
  58. c,c2: tmethodclass;
  59. r, ro: tmprec;
  60. meth: tmethod;
  61. shortpvar1,shortpvar2: tmyshortpvar;
  62. begin
  63. r.b:=21;
  64. ro.b:=42;
  65. c:=tmethodclass.create;
  66. c.l:=6;
  67. mypvar:=c.test;
  68. meth:=tmethod(mypvar);
  69. mypvar:=tmypvar(meth);
  70. mypvar(1,$ffff,r,ro);
  71. if r.b<>21 then
  72. raise jlexception.create('r changed');
  73. if ro.b<>123 then
  74. raise jlexception.create('ro not changed');
  75. c2:=tmethodclass.create;
  76. c2.l:=7;
  77. shortpvar1:=c.shorttest;
  78. shortpvar2:=c2.shorttest2;
  79. { should only copy the procedure pointer, not the instance ->
  80. instance.l=6, expected parameter = 130 }
  81. @shortpvar1:=@shortpvar2;
  82. shortpvar1(130);
  83. c.free;
  84. end.