Solved

Constructors, who is right?

Posted on 2004-08-19
1
190 Views
Last Modified: 2010-04-05
In the Delphi 7 help file it states:

"Create constructs an object. The purpose, size, and behavior of objects differ greatly. The Create constructor defined by TObject allocates memory but does not initialize data."

In Mastering Delphi 7 by Marco Cantu he says (on pg. 54) under Constructors:

"All of the data of the new instance is set to zero."

My question is, does the alllocated memory get initialized to zero, or not?

Regards,

Bill
0
Comment
Question by:wipnav
1 Comment
 
LVL 3

Accepted Solution

by:
KyleyHarris earned 50 total points
ID: 11848725
Yes, it does.

Any constructor defined by the key word constructor creates memory for the object and sets all bytes to 0. By saying it does not initialize data they mean that it does not set properties to predefined values. For Example. the default and stored keywords for published properties is not related;

property Color:TColor read FColor write FColor; default clGreen;

the constructor will not default the value to clGreen. This merely indicated that if the value equals the default value then do not stream it to a DFM

you still need to place

constructor createl
begin
  FColor := clGreen;
end;

otherwise it = 0
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Using idhttp to login to instagram 2 106
How to debug For loops? 3 57
Graphics32 under Delphi 10.1 Berlin 2 105
Firemonkey allowing RTL on android 6 47
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question