tclacla1.pp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. {$mode objfpc}
  2. type
  3. tbaseclass = class
  4. x : longint;
  5. class procedure virtual_class_method; virtual;
  6. class procedure call_virtual_class_method;
  7. end;
  8. tderivedclass = class(tbaseclass)
  9. y : longint;
  10. class procedure virtual_class_method; override;
  11. end;
  12. const
  13. tbasecalled : boolean = false;
  14. tderivedcalled : boolean = false;
  15. has_error : boolean = false;
  16. procedure tbaseclass.virtual_class_method;
  17. begin
  18. Writeln('Calling tbase class class method');
  19. tbasecalled:=true;
  20. end;
  21. class procedure tbaseclass.call_virtual_class_method;
  22. begin
  23. virtual_class_method;
  24. end;
  25. procedure tderivedclass.virtual_class_method;
  26. begin
  27. Writeln('Calling tderived class class method');
  28. tderivedcalled:=true;
  29. end;
  30. procedure reset_booleans;
  31. begin
  32. tbasecalled:=false;
  33. tderivedcalled:=false;
  34. end;
  35. var
  36. c1,cb : tbaseclass;
  37. cd : tderivedclass;
  38. cc : class of tbaseclass;
  39. begin
  40. cb:=tbaseclass.create;
  41. cd:=tderivedclass.create;
  42. c1:=tbaseclass.create;
  43. tbaseclass.virtual_class_method;
  44. if not tbasecalled then
  45. has_error:=true;
  46. reset_booleans;
  47. tbaseclass.call_virtual_class_method;
  48. if not tbasecalled then
  49. has_error:=true;
  50. reset_booleans;
  51. tderivedclass.virtual_class_method;
  52. if not tderivedcalled then
  53. has_error:=true;
  54. reset_booleans;
  55. tderivedclass.call_virtual_class_method;
  56. if not tderivedcalled then
  57. has_error:=true;
  58. reset_booleans;
  59. c1.virtual_class_method;
  60. if not tbasecalled then
  61. has_error:=true;
  62. reset_booleans;
  63. c1.call_virtual_class_method;
  64. if not tbasecalled then
  65. has_error:=true;
  66. reset_booleans;
  67. c1.destroy;
  68. c1:=tderivedclass.create;
  69. c1.virtual_class_method;
  70. if not tderivedcalled then
  71. has_error:=true;
  72. reset_booleans;
  73. c1.call_virtual_class_method;
  74. if not tderivedcalled then
  75. has_error:=true;
  76. reset_booleans;
  77. c1.destroy;
  78. cc:=tbaseclass;
  79. cc.virtual_class_method;
  80. if not tbasecalled then
  81. has_error:=true;
  82. reset_booleans;
  83. cc.call_virtual_class_method;
  84. if not tbasecalled then
  85. has_error:=true;
  86. reset_booleans;
  87. cc:=tderivedclass;
  88. cc.virtual_class_method;
  89. if not tderivedcalled then
  90. has_error:=true;
  91. reset_booleans;
  92. cc.call_virtual_class_method;
  93. if not tderivedcalled then
  94. has_error:=true;
  95. reset_booleans;
  96. if has_error then
  97. begin
  98. Writeln('Error with class methods');
  99. halt(1);
  100. end;
  101. end.