问题
When I declare a global variable in [Code]
section (Pascal Script) of Inno Setup script, is it automatically initialized to zero/empty value? Or do I have to explicitly initialize it (e.g. in InitializeSetup event function)?
var
GlobalNumber: Integer;
function InitializeSetup(): Boolean;
begin
{ Is this necessary? }
GlobalNumber := 0;
Result := True;
end;
From my experience, the variables are zero-initialized. Though, I'm not sure if I just have not been lucky.
I've done 10.000 iterations of a test code. The global variables (or various types, integer, string, pointer) were always zero-initialized.
回答1:
Variables are automatically initialized in Pascal Script afaik.
I thought that I also read this in earlier times somewhere in the docs, but I could not find a clear statement in documentation again. However, if you look at the examples from Pascal Script's official manual, variables are also not always initialized there. In the first code on this page for example, strings are added to Messages
without having it initialized before.
来源:https://stackoverflow.com/questions/34015970/are-global-variables-in-pascal-script-zero-initialized