为什么我们不能在inno-setup [Code]中声明局部const变量? [英] Why we cannot declare local const variables in inno-setup [Code]?
问题描述
您知道为什么在声明 local const vars 时,脚本无法编译吗?
对不起,我很少知道Pascal,无法弄清为什么它不起作用!
Do you know why when declaring local const vars, the script cannot compile? Sorry, I know very little pascal and cannot figure out why this is not working!
此示例(请参见 功能CircleArea )表明我的语法应该没问题。
http://www.tutorialspoint.com/pascal/pascal_quick_guide.htm
这就是我要执行的操作:
This is what I am trying to do:
//---placed within [Code]
procedure MyLog(const _functionName, _msg: String);
begin
Log(_functionName + '(): ' + _msg);
end;
function MyExec(const _filename, _params, _dir: String): Boolean;
const // <--- compilation fails in this line!
MethodName = 'MyExec';
var
ResultCode: Integer;
begin
MyLog(MethodName, _filename);
// ... invoke Exec(), etc. ...
end;
//---
推荐答案
尽力而为。如果Inno Setup使用Pascal,它甚至可以工作,但由于它基于自定义 Pascal脚本
语言在声明局部常量方面有局限性,您不能那样做。您必须改为全局定义常量:
You were trying that right. If Inno Setup were using Pascal it would even work, but since it is based on a custom Pascal Script
language with limitation on declaring local constants, you can't do it that way. You must define your constant globally instead:
[Code]
const
MethodName = 'MyExec';
function MyExec(const _filename, _params, _dir: String): Boolean;
var
ResultCode: Integer;
begin
MyLog(MethodName, _filename);
// ... invoke Exec(), etc. ...
end;
这篇关于为什么我们不能在inno-setup [Code]中声明局部const变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!