tclass2.pp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. { %VERSION=1.1 }
  2. {$mode objfpc}
  3. type
  4. to1 = class
  5. destructor destroy;override;
  6. procedure beforedestruction;override;
  7. end;
  8. to2 = class(to1)
  9. destructor destroy;override;
  10. procedure beforedestruction;override;
  11. end;
  12. var
  13. i : longint;
  14. destructor to1.destroy;
  15. begin
  16. writeln('to1.destroy');
  17. if i<>2000 then
  18. halt(1);
  19. i:=3000;
  20. inherited destroy;
  21. end;
  22. procedure to1.beforedestruction;
  23. begin
  24. writeln('to1.beforedestruction');
  25. if i<>1000 then
  26. halt(1);
  27. i:=2000;
  28. end;
  29. destructor to2.destroy;
  30. begin
  31. writeln('to2.destroy');
  32. if i<>4000 then
  33. halt(1);
  34. i:=2000;
  35. inherited destroy;
  36. i:=5000;
  37. end;
  38. procedure to2.beforedestruction;
  39. begin
  40. writeln('to2.beforedestruction');
  41. if i<>3000 then
  42. halt(1);
  43. i:=4000;
  44. end;
  45. var
  46. o1 : to1;
  47. o2 : to2;
  48. begin
  49. o1:=to1.create;
  50. o2:=to2.create;
  51. i:=1000;
  52. o1.destroy;
  53. o2.destroy;
  54. if i<>5000 then
  55. halt(1);
  56. writeln('ok');
  57. end.