tbs0187.pp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. { $OPT=-St -Cr }
  2. program test;
  3. {$ifdef go32v2}
  4. uses dpmiexcp;
  5. {$endif go32v2}
  6. type
  7. Tbaseclass = object
  8. base_arg : longint;
  9. st_count : longint;static;
  10. constructor Init;
  11. destructor Done;
  12. procedure Run; virtual;
  13. end;
  14. Totherclass = object(Tbaseclass)
  15. other_arg : longint;
  16. procedure Run; virtual;
  17. end;
  18. const
  19. BaseRunCount : integer = 0;
  20. OtherRunCount : integer = 0;
  21. constructor Tbaseclass.Init;
  22. begin
  23. writeln('Init');
  24. Inc(st_count);
  25. Run;
  26. end;
  27. destructor Tbaseclass.Done;
  28. begin
  29. writeln('Done');
  30. dec(st_count);
  31. end;
  32. procedure Tbaseclass.Run;
  33. begin
  34. writeln('Base method');
  35. inc(BaseRunCount);
  36. end;
  37. procedure Totherclass.Run;
  38. begin
  39. writeln('Inherited method');
  40. inc(OtherRunCount);
  41. end;
  42. { try this as local vars }
  43. procedure test_local_class_init;
  44. var base1 : TbaseClass;
  45. var other1 : TOtherClass;
  46. begin
  47. with other1 do
  48. Init;
  49. with base1 do
  50. Init;
  51. with other1 do
  52. begin
  53. Writeln('number of objects = ',st_count);
  54. base_arg:=2;
  55. other_arg:=6;
  56. Run;
  57. end;
  58. { test if changed !! }
  59. if (other1.base_arg<>2) or (other1.other_arg<>6) then
  60. Halt(1);
  61. with base1 do
  62. begin
  63. Run;
  64. Done;
  65. end;
  66. other1.done;
  67. end;
  68. var base : Tbaseclass;
  69. other : Totherclass;
  70. testfield : longint;
  71. begin
  72. // Uncommenting here and commenting the init in the WIth solves it.
  73. // Base.Init;
  74. with base do
  75. begin
  76. Init;
  77. Run;
  78. Done;
  79. end;
  80. // Uncommenting here and commenting the init in the WIth solves it.
  81. // Other.init;
  82. with other do
  83. begin
  84. Init;
  85. Run;
  86. Done;
  87. end;
  88. test_local_class_init;
  89. { Calls Tbaseclass.Run when it should call Totherclass.Run }
  90. If (BaseRunCount<>4) or (OtherRunCount<>4) then
  91. Begin
  92. Writeln('Error in tbs0187');
  93. Halt(1);
  94. End;
  95. end.