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 - 1 downto 0 do
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;