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

Sven Barth pascaldragon at googlemail.com
Tue Sep 24 16:59:30 CEST 2013


Am 24.09.2013 16:40, schrieb Dennis Poon:
>
>
> Sven Barth wrote:
>>> does Advanced Record constructor automatically zero all the memory 
>>> space of that record?
>> No, it does not. Neither in Delphi nor in FPC.
>>
>> Am 24.09.2013 12:36, schrieb Dennis Poon:
>>> if not, is there a clean and easy way to initialize the entire 
>>> record memory space to zeros e.g.
>>>
>>> constructor TMyRecord.Create(TheValue : Integer);
>>> begin
>>>   FillChar(self, sizeof(Self), 0);
>>>   Value := TheVal;
>>> end;
>> 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)
>>> Is there a Self variable for advanced record methods/constructors ?
>> Yes.
>>> By the way, is there an ultimate inherited constructor "Create" for 
>>> all advanced record types?
>> No.
>>
>> Regards,
>> Sven
>>
>
> Thanks for your help.
>
> Are the above info. available anywhere in FPC's web site that I 
> overlooked?  If not, maybe it should be added to its wiki.
Both points should be added to the documentation, but since they both 
are implemented only in trunk this is not the case yet.

Default() is also mentioned here: 
http://wiki.lazarus.freepascal.org/FPC_New_Features_Trunk#New_compiler_intrinsic_Default

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20130924/e965e3b8/attachment.html>


More information about the fpc-pascal mailing list