[fpc-pascal] Re: Initializing Records Automatically

L L at z505.com
Mon Mar 24 14:10:57 CET 2008


One thing to ponder about:

A class inside a record...
trecord = record
  something: TSomeClass;
  int: integer;
  //... etc
end;

My brain hurts.

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

I wouldn't use this normally (a class inside a record), but it is still 
interesting to think about.. for a standardized initialization system 
for records..

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.

We need to improve safety of our programs through automated methods..we 
aren't programming in C!

(I recently noticed the compiler has some detection switch for 
uninitialized variables and have yet to try it.. sounds like a cool 
testing ability) 

It is nice to have the performance benefit of non initialized records 
*but* at the same time it is nice to use SAFE features explicitely if we 
can.

I am *all for* an "autoinit" record switch feature, but then this breaks 
compatibility with delphi if such a feature is thought up. Maybe I 
suggest it in the "Delphi Wikia" website too just as useful pondering if 
anything.

procedure test;
var rec: AnyRecEvenWithInts AUTOINIT;
begin
end;

Are there are issues to think about if the classes are stored inside 
that record ? That may mean it is not such an easy feature to 
implement... or is it?

In the mean time, I will experiment with the fillchar/finalize tricks 
with "simple" records containing ansistrings and integers and such 
things. I didn't really have sincerity about it, or a correct 
standardized way to do it, until discussing on this list regarding 
finalize() and such things.  Honestly, I didn't even know much about 
fillchar due to my lack of "turbopascal record" experience. I've always 
been manually initializing my records and a pain in the butt that is.



More information about the fpc-pascal mailing list