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 typetype
.
In your case,
var MyGlobalVar: Integer = 16;