主窗体源代码
unit MainFrm;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Menus, ComCtrls, ToolWin;type
  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    ToolBar1: TToolBar;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    F1: TMenuItem;
    fsdf1: TMenuItem;
    fsdfsd1: TMenuItem;
    fdsfds1: TMenuItem;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;  procedure ShowForm(MainApp: TApplication); stdcall; external 'DLL.dll' name 'ShowForm';
  
var
  Form1: TForm1;implementation{$R *.dfm}procedure Search(Position: Integer);
begin
  ShowMessage(IntToStr(Position));
end;procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowForm(Application);
end;end.//dll源代码
library DLL;{ 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
  Windows,
  SysUtils,
  Classes,
  Dialogs,
  Forms,
  DllFrm in 'DllFrm.pas' {ChildForm};{$R *.res}var
  DllApp: TApplication;procedure ShowForm(MainApp: TApplication); stdcall;
begin
  if not Assigned(DllApp) then
  begin
    DllApp := Application;
    Application := MainApp;
  end;  Application.CreateForm(TChildForm, ChildForm);
end;procedure DllEntryPoint(dwReason: Integer);
begin
  if dwReason = DLL_PROCESS_DETACH then
  begin
    if Assigned(DllApp) then
      Application := DllApp;
  end;
end;exports
  ShowForm;begin
  DllProc := @DllEntryPoint;
end.