别为的代码,你看一下吧
procedure Tmainfrm.loadpkbyname(pkname:string);
var
pkobject:THandle;
CreateNewObject:TCreateNewObject;
begin
pkname:='PKlib/'+pkname;
// package dir
pkobject:=Loadpackage(pkname);
@CreateNewObject:=GetprocAddress(pkobject,'CreateObject');
if integer(@CreateNewObject)<0 then
application.messagebox('包加载失败!','Load Package',48)
else
createnewobject;
end;
2.动态释放Package比较麻烦,这里是李维的一个例子,应该可以:
procedure UnLoadAddInPackage(Module: THandle);
var
i: Integer;
M: TMemoryBasicInformation;
begin
{ Make sure there aren't any instances of any of the classes from Module
instantiated, if so then
free them. (this assumes that the classes are
owned by the application) }
for i := Application.ComponentCount - 1do
wnto 0do
begin
VirtualQuery(GetClass(Application.Components.ClassName), M, SizeOf(M));
if (Module = 0) or (HMODULE(M.AllocationBase) = Module) then
begin
ShowMessage(Application.Components.ClassName);
Application.Components.Free;
end;
end;
UnRegisterModuleClasses(Module);
UnLoadPackage(Module);
end;