Why we cannot declare local const variables in inno-setup [Code]?

混江龙づ霸主 提交于 2019-12-10 14:53:29

问题


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!

This example (see function CircleArea) shows that my syntax should be fine. 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;
//---

回答1:


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;


来源:https://stackoverflow.com/questions/18771167/why-we-cannot-declare-local-const-variables-in-inno-setup-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!