F
foreat
Unregistered / Unconfirmed
GUEST, unregistred user!
打包的单元(包名:myfirst_bpl.bpl)
**************************************************
unit myfirst_unit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
Tmyfirst = class(TForm)
Label1: TLabel;
private
{ Private declarations }
public
procedure justtest;
{ Public declarations }
end;
var
myfirst: Tmyfirst;
implementation
{$R *.DFM}
procedure Tmyfirst.justtest;
begin
showmessage('ok');
end;
initialization
RegisterClass(Tmyfirst);
end.
调用单元
******************************************************
unit bpl_test;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
myhmodule : HMODULE;
myClass: TPersistentClass;
myForm : TCustomForm;
{ Private declarations }
public
procedure loadbpl;
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
const
procedure tform1.loadbpl;
begin
try
myhmodule := loadpackage('myfirst_bpl.bpl');
myclass := GetClass('Tmyfirst');
if myclass <> nil then
myform := TCustomForm(TComponentClass(myclass).create(application));
except
showmessage('SomeThing Went Wrong!');
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
loadbpl;
end;
end.
问题是
****************************************
getclass时没有成功,myclass = nil,错在哪呢?请赐教!特急!
**************************************************
unit myfirst_unit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
Tmyfirst = class(TForm)
Label1: TLabel;
private
{ Private declarations }
public
procedure justtest;
{ Public declarations }
end;
var
myfirst: Tmyfirst;
implementation
{$R *.DFM}
procedure Tmyfirst.justtest;
begin
showmessage('ok');
end;
initialization
RegisterClass(Tmyfirst);
end.
调用单元
******************************************************
unit bpl_test;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
myhmodule : HMODULE;
myClass: TPersistentClass;
myForm : TCustomForm;
{ Private declarations }
public
procedure loadbpl;
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
const
procedure tform1.loadbpl;
begin
try
myhmodule := loadpackage('myfirst_bpl.bpl');
myclass := GetClass('Tmyfirst');
if myclass <> nil then
myform := TCustomForm(TComponentClass(myclass).create(application));
except
showmessage('SomeThing Went Wrong!');
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
loadbpl;
end;
end.
问题是
****************************************
getclass时没有成功,myclass = nil,错在哪呢?请赐教!特急!