bug0292.pp 696 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. {$mode objfpc}
  2. type
  3. pobj = ^tobj;
  4. tobj = object
  5. a: ansistring;
  6. constructor init(s: ansistring);
  7. destructor done;
  8. end;
  9. PAnsiRec = ^TAnsiRec;
  10. TAnsiRec = Packed Record
  11. Maxlen,
  12. len,
  13. ref : Longint;
  14. First : Char;
  15. end;
  16. const firstoff = sizeof(tansirec)-1;
  17. var o: pobj;
  18. t: ansistring;
  19. constructor tobj.init(s: ansistring);
  20. begin
  21. a := s;
  22. end;
  23. destructor tobj.done;
  24. begin
  25. end;
  26. begin
  27. readln(t);
  28. writeln('refcount before init: ',pansirec(pointer(t)-firstoff)^.ref);
  29. new(o,init(t));
  30. writeln('refcount after init: ',pansirec(pointer(t)-firstoff)^.ref);
  31. dispose(o,done);
  32. writeln('refcount after done: ',pansirec(pointer(t)-firstoff)^.ref);
  33. end.