我有一个InnoSetup项目,我希望能够根据发送到安装exe的命令行参数来设置InfoAfterFile。有办法吗?在这种情况下是否可以使用类似“检查”参数的功能?
您不能InfoAfterFile
在运行时为指令分配值。它的值指定了要编译到输出设置中的文件,因此必须在编译时知道此伪指令值。但是,您可以手动将文件加载到InfoAfterMemo
控件中。以下示例显示-iaf
仅当存在命令行参数指定的文件并且该文件存在时,如何加载该文件:
[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
InfoAfterFile=c:\DefaultFileToBeDisplayed.txt
[Code]
const
InfoAfterFileParam = '-iaf';
function TryGetInfoAfterFileParam(var FileName: string): Boolean;
var
S: string;
I: Integer;
Index: Integer;
begin
// initialize result
Result := False;
// iterate all the command line parameters
for I := 1 to ParamCount do
begin
// store the current parameter to the local variable
S := ParamStr(I);
// try to find the position of the substring specified by the
// InfoAfterFileParam constant; in this example we're looking
// for the "-iaf" string in the current parameter
Index := Pos(InfoAfterFileParam, S);
// if the InfoAfterFileParam constant string was found in the
// current parameter, then...
if Index = 1 then
begin
// strip out the InfoAfterFileParam constant string from the
// parameter string, so we get only file name
Delete(S, Index, Length(InfoAfterFileParam));
// now trim the spaces from rest of the string, which is the
// file name
S := Trim(S);
// check if the file pointed by the file name we got exists;
// if so, then return True for this function call and assign
// the output file name to the output parameter
if FileExists(S) then
begin
Result := True;
FileName := S;
end;
// we've found the parameter starting with InfoAfterFileParam
// constant string, so let's exit the function
Exit;
end;
end;
end;
procedure InitializeWizard;
var
FileName: string;
begin
// when the parameter was found and the file to be loaded exists,
// then load it to the InfoAfterMemo control
if TryGetInfoAfterFileParam(FileName) then
WizardForm.InfoAfterMemo.Lines.LoadFromFile(FileName);
end;
请注意,您将必须指定InfoAfterFile
指令,否则该页面将不会显示。另请注意,我正在寻找以开头的命令行参数-iaf
,因此,如果希望使用eg-iafx
参数,则需要实际修改此代码。这是从命令行进行此类设置的示例调用:
Setup.exe -iaf"C:\SomeFolder\SomeFileToBeShownAsInfoAfter.txt"
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句