使用Delphi进行安装 [英] Make an installer with Delphi
本文介绍了使用Delphi进行安装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的项目中,我有一些文件要复制到程序文件目录中,并为一个可执行文件和其他工作(如安装)创建快捷方式.
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.
我想在我的应用程序中使用Packages中的文件存储文件(例如CAB文件)并在进度栏中显示安装.
I want to do this in my application with store files in Packages, like CAB files and show installation in a progress bar.
首先,我想到了一个msi包装器,但是一些用户说这太慢了!
First I think about a msi wrapper, but some users said that is so slow!
我该如何以最佳方式做到这一点?
How can I do this in best way?
推荐答案
以下是开始的小模板:
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.
这篇关于使用Delphi进行安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文