如何在"PrepareToInstall"过程中显示进度? [英] How to show progress during "PrepareToInstall"?

查看:123
本文介绍了如何在"PrepareToInstall"过程中显示进度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用的安装程序会在PrepareToInstall函数中完成其大部分工作,因为我需要做的一切都可能会失败,因此这是处理这些错误的适当位置.通过在函数的结果中传递错误消息,可以自动报告任何故障.安装程序实际上仅复制3个小文件.

An installer I'm working on does most of its work in the PrepareToInstall function, as everything I need to do might fail, and therefore this is the appropriate place to handle these things in case they do fail. Any failure can be automatically reported by passing the error message in the function's result. There are only 3 small files which the installer actually copies over.

问题在于向导似乎在此功能期间冻结(或没有响应),只是显示了一个标题为准备安装..."的空白页面,而实际上,它正在我的安装过程中进行.

The problem is that the wizard seems to freeze (or not respond rather) during this function, just showing a blank page titled "Preparing to install..." while in reality, it's going through my install process.

我想通过一个简单的过程ShowProgress(const S: String);向用户显示进度,该过程向用户显示其实际操作.我该怎么办?

I would like to show the progress to the user with a simple procedure ShowProgress(const S: String); which shows the user what it's actually doing. How can I do this?

这就是我的安装方式,我希望将每个调用包装到Log() ...

This is how I'm doing my install, where I'd like to wrap each call to Log()...

function PrepareToInstall(var NeedsRestart: Boolean): String;
var
  R: Integer;
begin
  Result:= '';
  try
    Log('Doing this...');
    R:= DoThis;
    case R of
      0: begin
        Result:= '';
      end;
      1: begin
        Result:= 'Error message 1 was raised while doing this.';
      end;
      else begin
        Result:= 'Unexpected error doing this: ' + IntToStr(R);
      end;
    end;

    if Result = '' then begin
      Log ('Doing that...');
      R:= DoThat;
      case R of
        0: begin
          Result:= '';
        end;
        1: begin
          Result:= 'Error message 1 was raised while doing that.';
        end;
        else begin
          Result:= 'Unexpected error doing that: ' + IntToStr(R);
        end;
      end;
    end;

    if Result = '' then begin
      Log ('Doing something else...');
      R:= DoSomethingElse;
      case R of
        0: begin
          Result:= '';
        end;
        1: begin
          Result:= 'Error message 1 was raised while doing something else.';
        end;
        else begin
          Result:= 'Unexpected error doing something else: ' + IntToStr(R);
        end;
      end;
    end;

    //A few more blocks like above

    //Error logging
    if Result <> '' then begin
      Log('FAILURE: '+Result);
    end;

  except
    Result:= 'EXCEPTION';
    Log('EXCEPTION');
  end;
end;

推荐答案

PrepareToInstall函数中编写的代码阻止Windows消息泵的处理,从而使向导窗体无响应.如果需要在此屏幕上看到许多控件,以显示进度条和要执行的步骤列表,则可以使用DLL内部的表单来完成此操作.确保此DLL中有一个线程可以执行实际的安装过程,并且仅更新GUI以向用户显示状态.例如,此DLL格式可以覆盖向导,甚至可以嵌入到自定义向​​导页面中的向导内部.想法是将安装代码从PrepareToInstall函数移到该线程内,只有这样,您才能在此过程中获得完全响应的GUI.在PrepareToInstall函数中,应该只有一个DLL调用来启动安装过程,该过程反过来显示DLL中的表格.

The code written in the PrepareToInstall function blocks the Windows message pump from processing, rendering the wizard form non-responsive. If many controls are needed to be visible in this screen, showing perhaps a progress bar and list of steps to take, this can be done with a form inside of a DLL. Make sure there is a thread in this DLL which does the actual install process, and only update the GUI to display the status to the user. This DLL form may overlay the wizard, or may even be embedded inside of the wizard in a custom wizard page, for example. The idea is to move your install code from the PrepareToInstall function to within this thread, and only then will you be able to achieve a fully responsive GUI during this process. From the PrepareToInstall function, there should be just one DLL call to initiate the install process, which in turn shows the form from the DLL.

结果可能看起来像这样(在作品中):

The result may look something like this (in the works):

这篇关于如何在"PrepareToInstall"过程中显示进度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆