使用Delphi制作安装程序

时间:2013-03-09 13:26:58

标签: delphi installer firemonkey delphi-xe3

在我的项目中,我有一些文件要复制到程序文件目录中,并为一个可执行文件创建快捷方式,其他工作方式就像安装一样。

我希望在我的应用程序中使用Packages中的存储文件,例如CAB文件并在进度条中显示安装。

首先我想一个msi包装器,但有些用户说这太慢了!

我怎样才能以最佳方式做到这一点?

1 个答案:

答案 0 :(得分:4)

这是一个开始的小模板:

unit Unit1;

interface

uses
    Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
    StdCtrls
    , JwaMsi, windows // Units needed for MSI manipulation & for some type declarations

type

    { TForm1 }

    TForm1 = class(TForm)
        btnDoIt: TButton;
        lbxMsg: TListBox;
        procedure btnDoItClick(Sender: TObject);
    private
        { private declarations }
    public
        { public declarations }
    end;

var
    Form1: TForm1;

implementation

{$R *.dfm}

// Callback function
// Here you must handle type and content of messages from MSI (see MSDN for details)
function MSICallback(pvContext: LPVOID; iMessageType: Cardinal; szMessage: LPCSTR): Integer; stdcall;
var
    s: string;
begin
    // Convert PChar to string. Just for convenience.
    s := szMessage;

    // Add info about message to the ListBox
    Form1.lbxMsg.Items.Add(Format('Type: %d, Msg: %s', [iMessageType, s]));

    // Repaint form (may be it is not necessary)
    Form1.Refresh;
    Application.ProcessMessages;

    If iMessageType = INSTALLMESSAGE_TERMINATE then
        ShowMessage('Done');
end;

{ TForm1 }

procedure TForm1.btnDoItClick(Sender: TObject);
begin
    // Do not show native MSI UI
    MsiSetInternalUI(INSTALLUILEVEL_NONE + INSTALLUILEVEL_SOURCERESONLY, nil);

    // Set hook to MSI
    MsiSetExternalUI(
        @MSICallback, // Callback function
        $FFFFFFFF,    // Receive all types of messages
        nil);

    // Install product (change path to installation package)
    MsiInstallProduct(
        'D:\install\games\_old\corewar\nMarsFull.0.9.5.win.msi',
        nil);
end;

end.