Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls; Type // late binding, that is, to call an external function dynamically, use the following three commands: // loadlibrary: Get DLL // getprocaddress: Get function // freelibrary: Release // define a process type, the parameter must be consistent with the required function. TMB = function (hwnd: hwnd; lptext, lpcaption: pchar; utype: uint): integer; stdcall; tform1 = Class (tform) button1: tbutton; procedure button1click (Sender: tobject); Procedure formcreate (Sender: tobject); Procedure formdestroy (Sender: tobject); Private MB: TMB; {declaration function MB} inst: longword; {declare a variable to record the DLL handle to be used} public {public declarations} end; var form1: tform1; implementation {$ R *. DFM} procedure tform1.formcreate (Sender: tobject); begin inst: = loadlibrary ('user32. dll '); If inst 0 then MB: = getprocaddress (Inst, 'messageboxw'); // MB: = getprocaddress (Inst, 'messageboxa '); {use this sentence for versions earlier than Delphi 2009} end; // call the test: Procedure tform1.button1click (Sender: tobject); var T, B: pchar; begin T: = 'title '; b: = 'content'; MB (0, B, T, 0); end; Procedure tform1.formdestroy (Sender: tobject); begin freelibrary (insT); {remember to release} end; end.