加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

函数 – 在Inno Setup中实现脚本常量时的“标识符预期”或“无效

发布时间:2020-12-15 04:17:50 所属栏目:大数据 来源:网络整理
导读:因此,给定此函数,我在GetRoot上得到错误“Identifier Expected”:= ROOTPage.Values [0];线.我希望它告诉我ROOTPage没有定义? const DefaultRoot = 'C:IAmGRoot';Var ROOTPage : TInputQueryWizardPage;procedure SetupRoot;begin ROOTPage := CreateInpu
因此,给定此函数,我在GetRoot上得到错误“Identifier Expected”:= ROOTPage.Values [0];线.我希望它告诉我ROOTPage没有定义?
const
  DefaultRoot = 'C:IAmGRoot';
Var
  ROOTPage : TInputQueryWizardPage;

procedure SetupRoot;
begin
  ROOTPage := CreateInputQueryPage(wpUserInfo,ExpandConstant('{cm:RootTitle}'),ExpandConstant('{cm:RootInstructions}'),ExpandConstant('{cm:RootDescription}') + ' "' + DefaultRoot + '"'
    );

  ROOTPage.Add(ExpandConstant('{cm:SSRoot}') + ':',False);
  ROOTPage.Values[0] := ExpandConstant('{DefaultRoot}');

  // add SSROOT to path
end;

function GetRoot : string;
begin
  GetRoot := ROOTPage.Values[0];
end;

我该如何解释这个错误. Pascal中的标识符是什么?

这个page告诉我标识符是变量名.也许我需要以某种方式扩展ROOTPage.Values [0],因为我从Inno Setup对象引用了一个数组?

或许我需要以不同的方式返回值.我在Pascal上看到one page表示你需要避免在参数较少的函数上赋值函数以避免递归循环.这是否意味着我应该传递一个虚拟值?还是有不同的语法?该页面没有解释.

我暗自认为我的真正问题是我没有正确定义我的功能……但是很好.这至少可以编译.这个问题可能变成:你如何在Pascal中处理无参数函数?

我不认为Inno Setup是问题的一部分,但我正在与Inno Setup合作以防万一.

更新:
它似乎不是数组,因为它得到相同的错误:

const
  DefaultRoot = 'C:IAmGRoot';

function GetRoot : string;
begin
  GetRoot := DefaultRoot;
end;

更新:
这个link表示函数名称可以替换/应该用关键字Result替换,如下面的代码.我实际上知道这一点,但Inno Setup编译器并不认为这是有效的语法.然后它告诉我我的功能是一个无效的原型.

function GetRoot : string;
begin
  Result := DefaultRoot;
end;

更新:
如果我这样做,我得到“GetRoot的无效原型”

function GetRoot : boolean;
begin
  Result := False;
end;

@Martin Prikryl更新:

好吧,我在一些地方使用它,但典型的用途是这样的:

[Files]
Source: "C:ValidPathRelease*"; DestDir: "{app}bin"; Components: DefinedComponent
Source: "C:ValidPathDeployment*"; DestDir: "{code:GetRoot}"; Flags: ignoreversion recursesubdirs; Components: DefinedComponent

解决方法

标识符预期

您的代码在Pascal中是正确的,但它不能在Pascal脚本中编译.

在Pascal中,如果要分配函数的返回值,可以将值分配给具有函数名称的“变量”,也可以分配给Result变量.

所以这是正确的:

function GetRoot: string;
begin
  GetRoot := ROOTPage.Values[0];
end;

这也是(两者都是等价的):

function GetRoot: string;
begin
  Result := ROOTPage.Values[0];
end;

在Pascal脚本中,只有结果有效.当您使用该函数的名称时,您将获得“预期的标识符”.

原型无效

当从代码部分的超大尺寸调用函数并且需要特定的参数列表/返回值时,可以获得此结果.但是你没有告诉我们你使用GetRoot函数的原因.

有两个地方,您可以在Inno Setup中使用自定义功能:

> Check parameter:为此,函数必须返回一个布尔值,并且不带参数或一个参数(参数类型由您在Check参数中提供的值确定).

function MyProgCheck(): Boolean;

function MyDirCheck(DirName: String): Boolean;

> Scripted Constants:函数必须返回一个字符串并接受一个字符串参数,即使脚本常量中没有提供参数也是如此.我认为这是你的用例.如果您不需要任何参数,只需声明它,但不要使用它:

function GetRoot(Param: String): string;
begin
  Result := ROOTPage.Values[0];
end;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读