//xcqcheck.pas  dll库的实现部分
unit xcqcheck;interfaceuses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Mask;type
  Txcqform = class(TForm)
    xcqedit: TMaskEdit;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
     XcqForm: TXcqForm;
      Check: Boolean;//验证输入密码的正确性
      function CheckPassword: Boolean;export;implementation{$R *.DFM}procedure Txcqform.Button1Click(Sender: TObject);
begin
   if XcqEdit.Text = 'xcq' then begin
        Check := True;
        showmessage('password confirmed');
        end;
      Close;
end;function CheckPassword;export;
    begin
      Check := False;
      XcqForm := TXcqForm.Create(Application);
      XcqForm.ShowModal;//显示密码输入框;
      Result := Check;//返回给调用本dll的应用程序判断
      XcqForm.Free;//释放本dll文件所占资源
    end;end.//CheckPasswordForm.dpr,dll文件
library CheckPasswordForm;{ 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
      XcqCheck in 'XcqCheck.pas' {XcqForm};    exports
      CheckPassword name 'CheckPassword';//dll入口    begin
    end.
unit Unit1;//unit1.pas,调用例子interfaceuses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;implementation
function CheckPassword: Boolean; external 'CheckPasswordForm.dll' name 'CheckPassword';
{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
begin
if CheckPassword then 
    begin
showmessage('sdfdsf');
    end;
end;end.

解决方案 »

  1.   

    谢谢!
    其实我只想写一个对文件操纵的函数到DLL,不带窗口的,怎么做啊?
    还有编译出的DLL为什么不能增加版权信息???
      

  2.   

    //dll库
    library Project2;{ 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;{$R *.RES}function pingfang(x:integer):integer;
    begin
      result:=x*x;
    end;
      exports pingfang name 'pingfang';
    end.
    //调用

    var
      Form1: TForm1;implementation{$R *.DFM}
    function pingfang(x:integer):integer;external 'project2.dll';procedure TForm1.FormCreate(Sender: TObject);
    begin
    showmessage(inttostr(pingfang(50)));
    end;end.
      

  3.   

    版权信息No problem!!!
    project-->options-->version info -> 钩选 include version information in project,然后就随你填了
      

  4.   

    我不是说编译EXE文件下不可以改啊,是在编写DLL文件下不能改??
      

  5.   

    和普通的DLL一样啊!用DLL模板建一个框架,然后申明接口,其他和普通程序一样的!
      

  6.   

    I can modify the version information in a dll library,not a exe!
      

  7.   

    I suggest you re-install your Delphi!:)
      

  8.   

    我不明白exports pingfang name 'pingfang';这句是什么意思,如果有两个函数呢??