问题描述
我正在创建随机数,并在其他代码部分的多个地方使用它们。如果我使用/Create /F /SC DAILY /ST {code:MyRand}:{code:MyRand} ..."
,则直接在Code
部分中,它将在每次调用时生成随机数。但是我希望它在每次安装中仅创建一个随机数。那么如何将MyRand
的结果传递给变量,并在其他代码部分中使用该变量?
[Code]
function MyRand(Param: string): string;
begin
Result := IntToStr(Random(1000));
end;
解决方法
在安装程序启动时生成随机数,并在脚本化常量函数中引用生成的值。
var
MyRandValue: Integer;
function InitializeSetup(): Boolean;
begin
MyRandValue := Random(1000);
Result := True;
end;
function MyRand(Param: string): string;
begin
Result := IntToStr(MyRandValue);
end;