V
vine
Unregistered / Unconfirmed
GUEST, unregistred user!
请教一个Runtime package的问题
情况如下:
Main.dpr
包含文件uMain.pas, uMain.dfm
编译为Runtime package
demo.dpk
包含文件upkForm.pas,upkForm.dfm,upkFormIntf.pas
demo.dpk包代码
//-----------------------------------------------
unit upkFormIntf;
interface
type
IpkForm=Interface
['{171C7F88-DE69-421B-A863-D28B598C50B6}']
procedure ShowPKForm;
end;
implementation
end.
//-----------------------------------------------
unit upkForm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, upkFormIntf;
type
TpkfrmTest = class(TForm, IpkForm)
Button1: TButton;
private
public
procedure ShowPKForm;
end;
implementation
{$R *.dfm}
procedure TpkfrmTest.ShowPKForm;
begin
ShowModal;
end;
initialization
RegisterClass(TpkfrmTest);
finalization
UnRegisterClass(TpkfrmTest);
end.
//-----------------------------------------------
uMain.pas调用代码:
uses
upkFormIntf;
var
FHandle :THandle;
FForm : IpkForm;
AClass: TComponentClass;
begin
FHandle := LoadPackage('demo.bpl');
try
if @FHandle<>nil then
begin
AClass := TComponentClass(GetClass('TpkfrmTest'));
if AClass <> nil then
begin
//------ (A) ------
FForm := AClass.Create(nil) as IpkForm
FForm.ShowPKForm
FForm := nil;
//------ ------------
end
end;
finally
UnloadPackage(FHandle);
end;
end;
//-----------------------------------------------
问题出现在调用完的时候。TpkfrmTest是可以正常显示出现,也能在上面进行操作。
但在关闭时,在执行完UnloadPackage(FHandle);这句,直至end后,会报Access violation错误。
经过跟踪,demo.bpl已经释放
1)如果我注释了(A)段代码则没有问题
2)如果注释UnloadPackage(FHandle);这行代码也没有报错。
请问这是什么原因引起的,怎样解决?谢谢
情况如下:
Main.dpr
包含文件uMain.pas, uMain.dfm
编译为Runtime package
demo.dpk
包含文件upkForm.pas,upkForm.dfm,upkFormIntf.pas
demo.dpk包代码
//-----------------------------------------------
unit upkFormIntf;
interface
type
IpkForm=Interface
['{171C7F88-DE69-421B-A863-D28B598C50B6}']
procedure ShowPKForm;
end;
implementation
end.
//-----------------------------------------------
unit upkForm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, upkFormIntf;
type
TpkfrmTest = class(TForm, IpkForm)
Button1: TButton;
private
public
procedure ShowPKForm;
end;
implementation
{$R *.dfm}
procedure TpkfrmTest.ShowPKForm;
begin
ShowModal;
end;
initialization
RegisterClass(TpkfrmTest);
finalization
UnRegisterClass(TpkfrmTest);
end.
//-----------------------------------------------
uMain.pas调用代码:
uses
upkFormIntf;
var
FHandle :THandle;
FForm : IpkForm;
AClass: TComponentClass;
begin
FHandle := LoadPackage('demo.bpl');
try
if @FHandle<>nil then
begin
AClass := TComponentClass(GetClass('TpkfrmTest'));
if AClass <> nil then
begin
//------ (A) ------
FForm := AClass.Create(nil) as IpkForm
FForm.ShowPKForm
FForm := nil;
//------ ------------
end
end;
finally
UnloadPackage(FHandle);
end;
end;
//-----------------------------------------------
问题出现在调用完的时候。TpkfrmTest是可以正常显示出现,也能在上面进行操作。
但在关闭时,在执行完UnloadPackage(FHandle);这句,直至end后,会报Access violation错误。
经过跟踪,demo.bpl已经释放
1)如果我注释了(A)段代码则没有问题
2)如果注释UnloadPackage(FHandle);这行代码也没有报错。
请问这是什么原因引起的,怎样解决?谢谢