Name

AddModuleUnloadProc Procedure

Syntax

procedure AddModuleUnloadProc(Proc: TModuleUnloadProc);

procedure YourProcedure(HInstance: THandle);
begin ... end;
AddModuleUnloadProc(YourProcedure);

Description

Delphi keeps a list of packages that comprise an application. When Delphi unloads a package, it calls a series of unload procedures, passing the package DLL’s instance handle to each one. You can add your own unload procedure to the head of the list by passing its address to AddModuleUnloadProc. When the application exits, Delphi calls the module unload procedures for the application, too.

AddModuleUnloadProc is a real procedure.

Example

// The graphics server manages graphical resources. // When the application loads a graphical resource, the server // checks the color depth of the resource and if it is higher // than the color depth of the display, it makes a new copy of // the graphical object at the display's color depth, and returns // the new graphical object. Using a high-quality renderer // gives better results than letting Windows do the color matching. // // When a module is unloaded, free all of its resources. type PResource = ^TResource; TResource = record Module: THandle; Resource: TGraphicsObject; case Boolean of True: (Name: PChar;); False: (ID: LongInt;); end; var List: TList; procedure ByeBye(HInstance: THandle); var I: Integer; Resource: PResource; begin for I := List.Count-1 downto 0 do begin Resource := List[I]; if Resource.Module = HInstance then begin List.Delete(I); ...

Get Delphi in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.