Initialize static arrays in Freepascal

…Just in case I stumble again over that nasty “Variable of a managed type does not seem to be initialized” message and forgot how to get rid of it:

  • Create a type definition for the array you want to initialize, then use that defintion in “var”-section, too.
  • By doing so, we can use the “Default”-function to initialize the array and thus suppress that annoying compiler message:
type
  TMyStringArray = array[0..100] of string;

var
  MyStringArray: TMyStringArray;

begin
  MyStringArray := Default(TMyStringArray);
  ...
end.

That’s it! 🙂

Leave a comment

Your email address will not be published. Required fields are marked *