What is the meaning of the reintroduce and override directives in Delphi?

后端 未结 4 1595
余生分开走
余生分开走 2020-12-28 13:42

What is the difference between the override and reintroduce directives? And when should I not use the

4条回答
  •  死守一世寂寞
    2020-12-28 14:41

    There are many circumstances where you don't want to call inherited in an overridden method.

    In some libraries that I use, the base method throws an error (ENotImplimented or similar). Obviously in that case you don't want to call inherited or your code would also throw the error.

    Some of my classes have a default implementation that works in the majority of cases. The method is only overridden to replace the default, and there is no need to call the default.

    For example, the GST function (= sales tax) on my base financial object returns 12.5% of the ExGst amount and IncGst returns ExGst + GST.

    On my Income Compensation objects, GST always returns 0, so there is no need to call the inherited function.

提交回复
热议问题