2
0

INTF-CHANGES-0.99.12.txt 1.6 KB

1234567891011121314151617181920212223242526272829
  1. This document describes the API changes introduced in version 0.99.12 of PTCPas
  2. Since version 0.99.12, most PTCPas classes have been made descendants of
  3. TInterfacedObject and are now only accessible via interfaces. The reason for
  4. this change is to provide automatic memory management via reference counting for
  5. the PTC core objects, so that they are freed automatically, once they're no
  6. longer in use, without causing any memory leaks.
  7. Unfortunately, this breaks existing code. However, it's relatively easy to fix
  8. it and the purpose of this document is to explain how. Here's a basic summary
  9. of the changes that need to be made:
  10. 1) in your source code, replace "TPTCSomething.Create" with
  11. "TPTCSomethingFactory.CreateNew" (where 'Something' will correspond to one of
  12. those, depending on which objects are used in your program: Area, Color,
  13. Console, Event, Format, KeyEvent, Mode, MouseButtonEvent, MouseEvent, Palette,
  14. Surface and Timer)
  15. 2) replace "TPTCSomething" with "IPTCSomething" (where 'Something' = an object
  16. from point #1)
  17. 3) try compiling your code and you'll probably get some errors. Remove every
  18. call to .Free that fails with a compilation error, since it's no longer needed -
  19. PTC core objects are freed automatically when their reference count reaches
  20. zero.
  21. 4) if you are using FreeAndNil, be extra careful! Since it accepts an untyped
  22. var parameter (bad design coming from Delphi), it will not cause a compilation
  23. error, if you are using it on an interface, but you will instead get a crash at
  24. runtime. Sadly, there's not much you can do, besides checking every call to
  25. FreeAndNil and replacing it with ":= nil" when you're using it on a PTC core
  26. object.