Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6991027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:26:16+00:00 2026-05-27T19:26:16+00:00

In searching for a highly intermittent memory corruption in a Delphi XE program, I

  • 0

In searching for a highly intermittent memory corruption in a Delphi XE program, I have found a class constructor which initializes a few fields in the class, and then calls inherited. I believe the initializations were added after the constructor was first written, and accidentally in the wrong place. I have now corrected it to call inherited first. The exceptions from the memory corruption almost always occur in a method of this class.

Question: is it possible that this mistake caused an intermittent memory corruption? In tracing the code, it seems not, but I would really like this fix to be what solves the intermittent issue. That it does not occur for a while after fixing the problem will not prove that it has gone away.

Some code:

Tmyclass = class
  ctype : integer;
  ts : tstringlist;
  th : thandle;
public
  Constructor Create;
  Destructor Destroy; override;
  ...
end;

Constructor Tmyclass.Create;
begin
  ctype := 3;
  doinit;
  inherited;
end;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T19:26:17+00:00Added an answer on May 27, 2026 at 7:26 pm

    Here are typical steps of an object creation:

    • Memory allocation of the object instance;
    • Fill all memory with zero (to initialize all fields, especially string);
    • Call all nested constructors, beginning with the latest child, letting inherited call every parent – that is why you shall write inherited in both constructors and destructors.

    So, inherited calls the parent method – you can even specify a parent level, or call none if you are sure you can do that (but may break the SOLID principles).

    In fact, when a constructor is called, there is an hidden parameter added to the method:

    Constructors and destructors use the same calling conventions as other
    methods, except that an additional Boolean flag parameter is passed to
    indicate the context of the constructor or destructor call.

    A value of False in the flag parameter of a constructor call indicates
    that the constructor was invoked through an instance object or using
    the inherited keyword. In this case, the constructor behaves like an
    ordinary method. A value of True in the flag parameter of a
    constructor call indicates that the constructor was invoked through a
    class reference. In this case, the constructor creates an instance of
    the class given by Self, and returns a reference to the newly created
    object in EAX.

    A value of False in the flag parameter of a destructor call indicates
    that the destructor was invoked using the inherited keyword. In this
    case, the destructor behaves like an ordinary method. A value of True
    in the flag parameter of a destructor call indicates that the
    destructor was invoked through an instance object. In this case, the
    destructor deallocates the instance given by Self just before
    returning.

    The flag parameter behaves as if it were declared before all other
    parameters. Under the register convention, it is passed in the DL
    register. Under the pascal convention, it is pushed before all other
    parameters. Under the cdecl, stdcall, and safecall conventions, it is
    pushed just before the Self parameter.

    Source: official Delphi documentation

    So you can be sure that, wherever the inherited is called, it will be safely handled. For instance, initialization of fields (reset to 0) will be processed only once, before all constructors are called.

    The TObject.Create default constructor (the one called in your inherited line) is just a begin end void block, which does nothing. It is not even necessary/mandatory to call inherited here, but it is a good habit, since if you change your object hierarchy, it may be needed afterall.

    Only issue may be if some fields are set inside this inherited method (ctype := 2 e.g.), after having been set in the child – but this is not compiler’s fault, this is up to user code!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Searching online, I have found the following routine for calculating the sign of a
Searching for an answer I found this question , which is an exact opposite
Searching through the NVIDIA forums I found these questions , which are also of
Searching here I found that this question was already asked , but I think
Searching with '[Delphi] source control' didn't return much, so here goes: For those of
Im searching a tool which allows me to specify some folders as bookmarks and
I have been searching for a pure Java SSH library to use for a
I have a listview in which I am getting values from base adapter.what I
Searching one word works perfectly. I would like to have two or more words
I have the following models: class UserProfile(models.Model): user = models.OneToOneField(User) score = models.PositiveIntegerField() class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.