Make an installer with Delphi

核能气质少年 提交于 2019-12-25 07:38:16

问题


In my Project I have some files to copy in program files directory and make a shortcut for one executable and other works like an installation.

I want to do this in my application with store files in Packages, like CAB files and show installation in a progress bar.

First I think about a msi wrapper, but some users said that is so slow!

How can I do this in best way?


回答1:


Here is a small template for start:

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.


来源:https://stackoverflow.com/questions/15311196/make-an-installer-with-delphi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!