[fpc-devel] How to force the child's constructor to call its parent constructor

amir amir at aavani.net
Mon Oct 22 07:43:56 CEST 2007


Joao Morais wrote:
> amir wrote:
>> I want to force the all childs of TParent to call the Create 
>> constructor (with appropriate parameter). But one can implement a 
>> child class like this:
>>  constructor TChild.Create;
>>  begin
>> //     do any thing but not use inherited.
>>  end;
>
> No way. But you can override the NewInstance method; constructors will 
> call it for sure. You can also override the AfterConstruction method.
>
> -- 
> Joao Morais
How can I use the NewInstance or AfterConstruction methods for my 
purpose? I want to force the others to set ID. The TParent is written by 
me but anyone can write the TChild class.





More information about the fpc-devel mailing list