如何从PrepareToInstall事件函数设置StatusMsg

Kap*_*íko 3 inno-setup

我的应用程序需要安装.NET Framework,因此我在PrepareToIntall事件函数中运行.NET安装.在安装运行时,我想在向导上显示一些简单的消息.

我找到了如何在Inno安装脚本的[Code]部分设置状态消息?但那里的解决方案对我不起作用.

我试过了

WizardForm.StatusLabel.Caption := CustomMessage('InstallingDotNetMsg');
Run Code Online (Sandbox Code Playgroud)

并且

WizardForm.PreparingLabel.Caption := CustomMessage('InstallingDotNetMsg');
Run Code Online (Sandbox Code Playgroud)

编辑

我必须在PrepareToInstall函数中执行此操作,因为我需要在.net安装失败时停止设置.

代码现在看起来像这样:

function PrepareToInstall(var NeedsRestart: Boolean): String;
var 
   isDotNetInstalled : Boolean;
   errorCode : Integer;
   errorDesc : String;
begin
   isDotNetInstalled := IsDotNetIntalledCheck();
   if not isDotNetInstalled then 
   begin
      //WizardForm.PreparingLabel.Caption := CustomMessage('InstallingDotNetMsg');
      WizardForm.StatusLabel.Caption := CustomMessage('InstallingDotNetMsg');
      ExtractTemporaryFile('dotNetFx40_Full_x86_x64.exe');
      if  not ShellExec('',ExpandConstant('{tmp}\dotNetFx40_Full_x86_x64.exe'),'/passive /norestart', '', SW_HIDE, ewWaitUntilTerminated, errorCode) then
      begin
        errorDesc := SysErrorMessage(errorCode);
        MsgBox(errorDesc, mbError, MB_OK);
      end; 
      isDotNetInstalled := WasDotNetInstallationSuccessful();
      if not isDotNetInstalled then
      begin
         Result := CustomMessage('FailedToInstalldotNetMsg');
      end;
   end;
end;
Run Code Online (Sandbox Code Playgroud)

任何想法如何实现这一目标?

TLa*_*ama 9

StatusLabel被托管InstallingPage,而你的向导页面PreparingPage在页面PrepareToInstall事件的方法.所以这是一个错误的标签.您尝试将文本设置PreparingLabel为正确但是失败,因为该标签默认是隐藏的(当您将非空字符串作为结果返回到事件方法时显示).

但你可以显示它一段时间(你使用ewWaitUntilTerminated标志,所以你的安装是同步的,因此它不会伤害任何东西):

[Code]
function PrepareToInstall(var NeedsRestart: Boolean): String;
var
  WasVisible: Boolean;
begin
  // store the original visibility state
  WasVisible := WizardForm.PreparingLabel.Visible;
  try
    // show the PreparingLabel
    WizardForm.PreparingLabel.Visible := True;
    // set a label caption
    WizardForm.PreparingLabel.Caption := CustomMessage('InstallingDotNetMsg');
    // do your installation here
  finally
    // restore the original visibility state
    WizardForm.PreparingLabel.Visible := WasVisible;
  end;
end;
Run Code Online (Sandbox Code Playgroud)