一种快速但肮脏的解决方案来填充数字Inno安装预处理器 https://jrsoftware.org/ispphelp/:
#define AppVerText() \
GetVersionComponents('..\app\bin\Release\app.exe', \
Local[0], Local[1], Local[2], Local[3]), \
Str(Local[0]) + "." + \
(Local[1] < 10 ? "0" : "") + Str(Local[1]) + "." + \
(Local[2] < 100 ? "0" : "") + (Local[2] < 10 ? "0" : "") + Str(Local[2])
如果您想要填充的通用函数,请使用:
#define PadStr(S, C, L) Len(S) < L ? C + PadStr(S, C, L - 1) : S
像这样使用它:
#define AppVerText() \
GetVersionComponents('MyProg.exe', \
Local[0], Local[1], Local[2], Local[3]), \
Str(Local[0]) + "." + PadStr(Str(Local[1]), "0", 2) + "." + \
PadStr(Str(Local[1]), "0", 3)
帕斯卡脚本Code
(like this one https://stackoverflow.com/q/34698256/850848)在这里没有帮助,因为它在安装时运行,而您在编译时需要它。所以预处理器是唯一的方法。