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:
  TMyStringArray = array[0..100] of string;

  MyStringArray: TMyStringArray;

  MyStringArray := Default(TMyStringArray);

That’s it! 🙂

Leave a comment

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