[fpc-pascal] does Advanced Record constructor automatically zero all the memory space of that record?

Dennis Poon dennis at avidsoft.com.hk
Sat Oct 5 06:05:08 CEST 2013


Thanks a lot for clarification.

Dennis

Sven Barth wrote:
> On 04.10.2013 14:48, Dennis Poon wrote:
>>
>>
>> >You can use either FillChar as you did or use "Self :=
>> Default(TTest);" (default is a compiler intrinsics that returns a 0
>> value of the type >you passed in, e.g. Nil for classes, '' for strings,
>> 0 for ordinals and for records all fields are set to 0)
>>
>> How can I make it so that I only do the Self := Default() once in the
>> parent class constructor and don't have to repeat it in all its
>> descendant class constructor.
>
> Why would you want to do that? Classes are already zero initialized 
> when the constructor is entered.
> Also using "Self := Default(...)" inside a class would not do what you 
> expect it to do. "Self" is a class reference and thus "Default(...)" 
> of the same type would return "Nil" and thus set your "Self" for the 
> current method call to "Nil" (so you could no longer access the class 
> instance at all).
>
>> I noticed in your example, you have to specify the class name TTest but
>> that implies in every descendant class,  I have to replace it with the
>> Descendant class name.
>>
>> Can I do
>>    self := Default(ClassType) ?
>> hoping it will return the descendant's class type?
>
> Default expects a type identifier and nothing else. I currently don't 
> know whether Delphi supports more. But in any way it wouldn't change 
> much as Default(TObject) = Default(TSomeClass) = 
> Default(TSomeChildClass) = Nil.
>
> Regards,
> Sven
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
>
> -----
> No virus found in this message.
> Checked by AVG - www.avg.com
> Version: 2013.0.3408 / Virus Database: 3222/6723 - Release Date: 10/04/13
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20131005/31e52979/attachment.html>


More information about the fpc-pascal mailing list