Delphi generation that is calling with a form Dll

library frmDll;

{ Important note about DLL memory management: ShareMem must be the
  first unit in your library's USES clause AND your project's (select
  Project-View Source) USES clause if your DLL exports any procedures or
  functions that pass strings as parameters or function results. This
  applies to all strings passed to and from your DLL--even those that
  are nested in records and classes. ShareMem is the interface unit to
  the BORLNDMM.DLL shared memory manager, which must be deployed along
  with your DLL. To avoid using BORLNDMM.DLL, pass string information
  using PChar or ShortString parameters. }

uses
  SysUtils,
  Classes,
  Forms, 
  FormDll in  ' FormDll.pas '  { the Form1 } ; 

{ $ R & lt .res * } 

function GetDllForm: a TForm; _stdcall ; Export ; // define derivation method; 
the begin 
  Result: = the Form1; // function returns the type of a form ; 
End ;
 Exports 
  GetDllForm; // declare a method that can be exported; 

the begin 
End . 




Unit FormDll; 

interface 

uses 
  Windows, the Messages, the SysUtils, Variants, the Classes, Graphics, Controls, Forms, 
  the Dialogs, StdCtrls; 

of the type
  TForm1 = class (a TForm) 
    btn1: the TButton; 
    Procedure btn1Click (Sender: TObject);
   Private 
    { Private Declarations } 
  public 
    { Public Declarations } 
  End ; 

var 
  the Form1: TForm1; 

Implementation 

{ $ R & lt *. Dfm } 

Procedure TForm1.btn1Click (Sender: TObject);
 the begin 
  MessageDlg ( ' you have successfully call control Dll ' , mtinformation, [MBOK], 0 );
 end ; 

initialization  // before the end of the file is placed in a cell, comprising the code for the initialization unit, it is the main before the program runs only once to run and run
the begin 
  the Form1: = TForm1. the Create (the Application);
 end ; 

finalization // on initialization and end between the unit includes code units when the exit. When you exit the program run and run only once. 
the begin 
  Form1.Free; 
End ; 

End . 





Unit testdll; 

interface 

uses 
  Windows, the Messages, the SysUtils, Variants, the Classes, Graphics, Controls, Forms, 
  the Dialogs, StdCtrls; 

of the type 
  TForm1 = class (TForm) 
    btn1: TButton; 
    Procedure btn1Click (Sender: TObject);
   Private 
    { Private Declarations } 
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  //function GetDllForm:TForm;

implementation

{$R *.dfm}
function GetDllForm:TForm;external 'frmDll.dll';  //声明从函数frmDll.dll中调用函数


procedure TForm1.btn1Click(Sender: TObject);
var
  AForm:TForm;
begin
  AForm:=GetDllForm;
  AForm.Show;
end;

end.
 

Guess you like

Origin www.cnblogs.com/tobetterlife/p/12169918.html