[fpc-pascal] Re: Initializing Records Automatically

Jonas Maebe jonas.maebe at elis.ugent.be
Mon Mar 24 13:31:30 CET 2008


On 24 Mar 2008, at 14:10, L wrote:
> One thing to ponder about:
>
> A class inside a record...
> trecord = record
> something: TSomeClass;
> int: integer;
> //... etc
> end;
>
> My brain hurts.

A class field is just a pointer. Since classes are not reference  
counted, nothing special is done for record fields which are classes.

> This will cause issues with a Fillchar for the class, or not?

No.

> The idea is.. I want to create/ponder about a "standardized" way to  
> init ANY sort of record because a lot of silly bugs in pascal are  
> because of these uninitialized local scope records, or similar non  
> initialized things.

If you have local record which was declared but not yet used, a simple  
fillchar(rec,sizeof(rec),0) will set everything to 0/nil/empty. If it  
may have been used earlier and contains refcounted fields, you first  
have to call finalize(rec).

Or you can let the compiler decide whether or not finalize() is  
required by using a wrapper with an out-parameter like the blog guy did.

>

Jonas



More information about the fpc-pascal mailing list