以下是最初试用Bpl的笔记:
一、准备bpl:
1、注意注册类:这样可以找到,不会报“指针nil”错
2、编译选项runtime only
3、bpl输出目录改正
二、调用bpl
1、主工程:注意必须在选项package后勾上build with runtime package。
下面的文本框中的内容可以视情况删减。这里的含义并非静态的一次调入将
要调用的bpl。
2、以这样的方式调用
procedure TForm1.Button2Click(Sender: TObject);
var
h: HMODULE;
afrm: TForm;
begin
try
h := LoadPackage('C:/工作室/bpl框架/bplsecond.bpl');
afrm := TForm(TComponentClass(FindClass('Tform1')).Create(Application));
afrm.ShowModal;
finally
afrm.Free;
UnLoadPackage(h);
end;
end;
下面是完整的演示代码:
unit mainfrm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
h: HMODULE;
afrm: TForm;
begin
try
h := LoadPackage('C:/工作室/bpl框架/bplfirst.bpl');
afrm := TForm(TComponentClass(FindClass('Tform1')).Create(Application));
afrm.ShowModal;
finally
afrm.Free;
UnLoadPackage(h);
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
h: HMODULE;
afrm: TForm;
begin
try
h := LoadPackage('C:/工作室/bpl框架/bplsecond.bpl');
afrm := TForm(TComponentClass(FindClass('Tform1')).Create(Application));
afrm.ShowModal;
finally
afrm.Free;
UnLoadPackage(h);
end;
end;
end.