Is there a benefit in using old style `object` instead of `class` in Delphi?

前端 未结 4 1540
刺人心
刺人心 2020-12-31 15:31

In Delphi sane people use a class to define objects.
In Turbo Pascal for Windows we used object and today you can still use

4条回答
  •  遥遥无期
    2020-12-31 16:20

    Way back in older versions of Delphi which did not support records with methods then using object was the way to get your objects allocated on the stack. Very occasionally that would yield worthwhile performance benefits. Nowadays record is better. The only feature missing from record is the ability to inherit from another record.

    You give up a lot when you change from class to record so only consider it if the performance benefits are overwhelming.

提交回复
热议问题