tclass1.pp 1.1 KB

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