给你个例子:<br>library DllMdiChildForm;<br><br>{ Important note about DLL memory management: ShareMem must be the<br> first unit in your library's USES clause AND your project's (select<br> Project-View Source) USES clause if your DLL exports any procedures or<br> functions that pass strings as parameters or function results. This<br> applies to all strings passed to and from your DLL--even those that<br> are nested in records and classes. ShareMem is the interface unit to<br> the BORLNDMM.DLL shared memory manager, which must be deployed along<br> with your DLL. To avoid using BORLNDMM.DLL, pass string information<br> using PChar or ShortString parameters. }<br><br>uses<br> Windows,<br> Messages,<br> SysUtils,<br> Classes,<br> Graphics,<br> Controls,<br> Forms,<br> Dialogs,MSFlexGridLib_TLB,<br> UnitDll in 'UnitDll.pas' {Form1};<br><br>procedure ProvaChild(ParentApplication: TApplication; ParentForm:TForm;MSGrid:TMSFlexGrid); export; stdcall;<br>var<br> Form1: TForm1;<br> DllProc: Pointer; { Called whenever DLL entry point is called }<br><br>begin<br> Application:=ParentApplication;<br><br> Form1:=TForm1.Create(ParentForm);<br> Form1.MyParentForm:=ParentForm;<br> Form1.MyParentApplication:=ParentApplication;<br><br>// windows.SetParent(Form1.Handle,ParentForm.Handle);<br>// Form1.FormStyle:=fsMDIChild;<br> Form1.Button1.Caption :=inttostr(MsGrid.rows);<br> Form1.Show;<br>end;<br><br>procedure DLLUnloadProc(Reason: Integer); register;<br>begin<br> if Reason = DLL_PROCESS_DETACH then Application:=DllApplication;<br>end;<br><br>exports<br> ProvaChild;<br>begin<br> DllApplication:=Application;<br> DLLProc := @DLLUnloadProc;<br>end.<br>unit UnitDll;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> OleCtrls, MSFlexGridLib_TLB, StdCtrls;<br><br>type<br> TForm1 = class(TForm)<br> Button1: TButton;<br> MSFlexGrid1: TMSFlexGrid;<br> procedure FormClose(Sender: TObject; var Action: TCloseAction);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> MyParentForm: TForm;<br> MyParentApplication: TApplication;<br> end;<br><br>var<br> DllApplication: TApplication;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<br>begin<br> Action:=caFree;<br>end;<br><br>end.<br>unit MainFormUnit;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> Menus, StdCtrls, OleCtrls, MSFlexGridLib_TLB;<br><br>type<br> TForm1 = class(TForm)<br> MainMenu1: TMainMenu;<br> MDIChildForm1: TMenuItem;<br> Button1: TButton;<br> Grd: TMSFlexGrid;<br> procedure MDIChildForm1Click(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>T_ProvaChild = procedure (ParentApplication: TApplication; ParentForm: TForm;MSGrid : TMSFlexGrid); stdcall;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.MDIChildForm1Click(Sender: TObject);<br>var<br> DllHandle: THandle;<br> ProcAddr: FarProc;<br> ProvaChild: T_ProvaChild;<br>begin<br> DllHandle := LoadLibrary('DllMdiChildForm');<br> ProcAddr := GetProcAddress(DllHandle, 'ProvaChild');<br> if ProcAddr <> nil then<br> begin<br> ProvaChild := ProcAddr;<br> ProvaChild(Application,Self,Grd);<br> end;<br>end;<br><br>end.