Home > Mobile >  Is it possible to declare a global var with an initial value?
Is it possible to declare a global var with an initial value?

Time:11-17

Maybe I miss something, but is their a way to declare a global var in Delphi with an Initial value?

var MyGlobalVar: integer := 16;

This not work (but do work when the var is inlined in the code)

CodePudding user response:

Yes. From the documentation on variables:

Global variables can be initialized at the same time they are declared, using the syntax:

var identifier: type = constantExpression;

where constantExpression is any constant expression representing a value of type type.

In your case,

var MyGlobalVar: Integer = 16;
  • Related