ama*_*ate 6 syntax inno-setup function pascalscript
因此,给定此功能,我GetRoot := ROOTPage.Values[0];在行上收到错误"Identifier Expected" .我希望它告诉我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;
Run Code Online (Sandbox Code Playgroud)
我该如何解释这个错误.Pascal中的标识符是什么?
这个页面告诉我标识符是变量名.也许我需要以ROOTPage.Values[0]某种方式扩展它,因为我从Inno Setup对象引用一个数组?
或许我需要以不同的方式返回值.我在Pascal上看到一个页面表示你需要避免在参数较少的函数上分配函数值以避免递归循环.这是否意味着我应该传递一个虚拟值?还是有不同的语法?该页面没有解释.
我暗自认为我的真正问题是我没有正确定义我的功能......但是很好.这至少可以编译.这个问题可能变成:你如何在Pascal中处理无参数函数?
我不认为Inno Setup是问题的一部分,但我正在与Inno Setup合作以防万一.
更新: 它似乎不是数组,因为它得到相同的错误:
const
DefaultRoot = 'C:\IAmGRoot';
function GetRoot : string;
begin
GetRoot := DefaultRoot;
end;
Run Code Online (Sandbox Code Playgroud)
更新:
此链接表示函数名称可以替换/应替换为关键字Result,如下面的代码.我实际上知道这一点,但Inno Setup编译器并不认为这是有效的语法.然后它告诉我我的功能是一个无效的原型.
function GetRoot : string;
begin
Result := DefaultRoot;
end;
Run Code Online (Sandbox Code Playgroud)
更新: 如果我这样做,我得到"GetRoot的无效原型"
function GetRoot : boolean;
begin
Result := False;
end;
Run Code Online (Sandbox Code Playgroud)
@Martin Prikryl 更新:
好吧,我在一些地方使用它,但典型的用途是这样的:
[Files]
Source: "C:\ValidPath\Release\*"; DestDir: "{app}\bin"; Components: DefinedComponent
Source: "C:\ValidPath\Deployment\*"; DestDir: "{code:GetRoot}\"; Flags: ignoreversion recursesubdirs; Components: DefinedComponent
Run Code Online (Sandbox Code Playgroud)
Mar*_*ryl 13
您的代码在Pascal中是正确的,但它不能在Pascal脚本中编译.
在Pascal中,当您想要指定函数的返回值时,可以将值赋给具有函数名称的"变量"或Result变量.
所以这是正确的:
function GetRoot: string;
begin
GetRoot := ROOTPage.Values[0];
end;
Run Code Online (Sandbox Code Playgroud)
这也是(两者都是等价的):
function GetRoot: string;
begin
Result := ROOTPage.Values[0];
end;
Run Code Online (Sandbox Code Playgroud)
在Pascal脚本中,只有Result作品.当您使用该函数的名称时,您将获得"预期的标识符".
当从该Code部分的大小调用该函数并且需要特定的参数列表/返回值时,您可以获得此结果.但你没有告诉我们,你使用的GetRoot功能是什么.
有两个地方,您可以在Inno Setup中使用自定义功能:
Check参数:为此,函数必须返回a Boolean并且不带参数或一个参数(参数类型由您在Check参数中提供的值确定).
function MyProgCheck(): Boolean;
function MyDirCheck(DirName: String): Boolean;
Run Code Online (Sandbox Code Playgroud)脚本常量:函数必须返回a string并接受一个string参数,即使脚本常量中没有提供参数也是如此.我认为这是你的用例.如果您不需要任何参数,只需声明它,但不要使用它:
function GetRoot(Param: String): string;
begin
Result := ROOTPage.Values[0];
end;
Run Code Online (Sandbox Code Playgroud)| 归档时间: |
|
| 查看次数: |
3107 次 |
| 最近记录: |