constructor TCustomIniFile.Create(const FileName: string);

constructor TCustomIniFile.Create(const FileName: string);
begin
  FFileName := FileName;
end;

Been looking for a memory problem for a couple days. On a lark, I ran PAL to help find stuff. It pointed out Create() methods that didn't call "inherited" in the constructor. 

However, it found a couple in the XE2 source
System.Inifiles.TCustomIniFile.Create()
and 
System.Win.Registry.TRegistry.Create() and the overloaded version and the fancy class constructor

I was under the impression that one must pretty much always call inherited first, but then I saw this...

http://www.delphibasics.co.uk/RTL.asp?Name=Inherited

"It is called at the start of a constructor, and at the end of a desctructor. It is not mandatory, but recommended as good practice."

Ctrl-Click on inherited Create() for an Object, sure seems to have code that should go first (in all cases?).

So I guess I'm kind of confused on when inherited is NOT something you'd call each and every time and what happens if you don't...
http://www.delphibasics.co.uk/RTL.asp?Name=Inherited

Comments

  1. Marco Cantù Given the recent change in the implementation of TObject.Free, I wouldn't bet on that!

    ReplyDelete
  2. Uwe Raabe Well, my recommendation is to call inherited, just in case. Free changed (and in a very limited way) only in ARC compilers, with a radical change of the memory management model. In that you are right, there is no absolute guarantee.

    ReplyDelete
  3. Thanks for the fast answer Marco Cantù. I appreciate it. Funny, I used your books and didn't see the answer ; to think I'd get a response from you via G+ is hilarious. Thanks for you support!

    ReplyDelete

Post a Comment