tbs0187.pp 2.1 KB

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