如何在Inno Setup中的字符串中包含随机数?
[Run]
#define rndH Random(24)
#define rndM Random(60)
Filename: "schtasks"; \
Parameters: "/Create /F /SC DAILY /ST {rndH}:{rndM} /RU SYSTEM /RL HIGHEST /TN ""Program Title"" /TR ""'{app}\program.exe'""";
当我尝试上面的代码时,我收到错误
[ISPP]未声明的标识符:“随机”
由于
答案 0 :(得分:0)
如果有人有这样的问题,我设法用下面的代码来做。
[Run]
Filename: "schtasks"; \
Parameters: "/Create /F /SC DAILY /ST {code:MyRandH}:{code:MyRandM} /RU SYSTEM /RL HIGHEST /TN ""Program Title"" /TR ""'{app}\program.exe'""";
[Code]
var
h: Integer;
m: Integer;
function MyRandH(Param: String): String;
begin
h := Random(24);
if h < 10 then
Result := '0' + IntToStr(h)
else
Result := IntToStr(h);
end;
function MyRandM(Param: String): String;
begin
m := Random(60);
if m < 10 then
Result := '0' + IntToStr(m)
else
Result := IntToStr(m);
end;
答案 1 :(得分:0)
你的答案中的代码有效,但它不必要地复杂化:
Format
function将数字填充为两位数字; [Run]
Filename: "schtasks"; \
Parameters: "/Create /F /SC DAILY /ST {code:MyRand|24}:{code:MyRand|60} ...";
[Code]
function MyRand(Param: string): string;
begin
Result := Format('%.2d', [Random(StrToInt(Param))]);
end;