The general rule is that you should put code that needs to be called when your package is unloaded into the finalization
part of your unit. I know from your other package that you're trying to unload a dll. But the catch is that should never load/unload a dll from initialization
or finalization
.
So what you need to do is have a function in your package that you will call from your main application, that performs the clean-up.
type
TCleanup = procedure;
var
MyPackageHandle : THandle;
CleanupProc: TCleanup;
begin
MyPackageHandle := LoadPackage('.\MyPackage.bpl');
if(MyPackageHandle <> 0) then
begin
@CleanupProc := GetProcAddress(MyPackageHandle, 'Cleanup' );
if @CleanupProc <> nil then
CleanupProc;
UnloadPackage(MyPackageHandle);
end;
end;
initialization
andfinalization
work in this case maybe? – nil