I wrote an example that some netizens needed.
Please follow the instructions below if there is something wrong or unreasonable.
Delph Xe passed the test.
DLL project file
Library project10; uses sysutils, classes, forms, unit14 in 'unit14. PAS '{form1}; {$ R *. res} function edebtmoney (H: thandle): integer; begin application. handle: = H; with tform1.create (Application) Do try showmodal; Result: = 0; finally free; {destroy window when call ends} end; function getform (H: thandle): thandle; begin application. handle: = H; with tform1.create (Application) Do try show; Result: = handle; handle T on E: exception do raise E. create (E. message); end; exports edebtmoney, getform; beginend.
Form close event in DLL
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);begin Action := caFree;end;
Call Unit
Unit unit13; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls; Type tform13 = Class (tform) btn1: tbutton; btn2: tbutton; procedure btn1click (Sender: tobject); Procedure btn2click (Sender: tobject); Private {private Declarations} public {public declarations} end; var form13: tform13; function myform (H: thandle): thandle; stdcall; implementationfunction myform; External 'project10. DLL 'name' getform '; {$ R *. DFM} // call the modal window procedure tform13.btn1click (Sender: tobject); Type tgetform = function (H: thandle): integer; cdecl; var dllform: tgetform; dllhandle: thandle; NN: integer; begin dllhandle: = loadlibrary (pchar ('project10. dll '); try if dllhandle <> 0 then begin dllform: = getprocaddress (dllhandle, 'edebtmoney'); NN: = dllform (application. handle); self. caption: = inttostr (NN); end; finally freelibrary (dllhandle); end; // static call non-modal window procedure tform13.btn2click (Sender: tobject); var dllhandle: thandle; begin dllhandle: = myform (application. handle); end.