tw1365.pp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. {$mode tp}
  2. program test_const_objects;
  3. const
  4. top2_display_called : integer = 0;
  5. top3_display_called : integer = 0;
  6. type
  7. tobj1 = object
  8. x,y : integer;
  9. end;
  10. tobj2 = object(tobj1)
  11. z : integer;
  12. constructor init(ax,ay,az : integer);
  13. procedure display; virtual;
  14. end;
  15. tobj3 = object(tobj2)
  16. t : integer;
  17. constructor init(ax,ay,az,at : integer);
  18. procedure display; virtual;
  19. end;
  20. constructor tobj2.init(ax,ay,az : integer);
  21. begin
  22. x:=ax;
  23. y:=ay;
  24. z:=az;
  25. end;
  26. procedure tobj2.display;
  27. begin
  28. Writeln(x,' ',y,' ',z);
  29. inc(top2_display_called);
  30. end;
  31. constructor tobj3.init(ax,ay,az,at : integer);
  32. begin
  33. x:=ax;
  34. y:=ay;
  35. z:=az;
  36. t:=at;
  37. end;
  38. procedure tobj3.display;
  39. begin
  40. Writeln(x,' ',y,' ',z,' ',t);
  41. inc(top3_display_called);
  42. end;
  43. const
  44. Obj1 : Tobj1 = (x : 1; y : 2);
  45. Obj2 : TObj2 = (x : 3; y : 4; z : 5);
  46. Obj3 : Tobj3 = (x : 6; y : 7; z : 8; t : 9);
  47. Obj3b : Tobj3 = (x : 10);
  48. begin
  49. Obj2.Display;
  50. Obj3.Display;
  51. Obj3b.Display;
  52. if (top2_display_called<>1) or (top3_display_called<>2) then
  53. Halt(1);
  54. end.