请教个问题,我有个函数a,每次都调用b函数,其中a函数的内容是不变的,每个项目只需要修改b函数就可以了,有没有办法把a函数打包成动态库或dcu等,总之不用把源码提供给别人,别人只需要写b函数并调用a函数就可以了

解决方案 »

  1.   

    可以啊,你新建一个DLL Wizard,然后把函数写在里面,注意要声明调用的函数名称,要不别人没办法使用!
    简单的求和实例:{Dll部分}
    library addnum;{ 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}//在dll中定义求和函数
    function addnums(num1,num2:integer):integer;stdcall;
    begin
      result:=num1+num2; //返回两个整数的和
    end;
      exports               //引出求和函数
      addnums name 'addm';  //求和函数的别名
      
    begin
    end.
     
    {程序调用}
    unit main;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Edit1: TEdit;
        Edit2: TEdit;
        Edit3: TEdit;
        Button1: TButton;
        Label1: TLabel;
        Label2: TLabel;
        Label3: TLabel;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation
    //主程序在调用该DLL时,首先声明要调用的函数
    function addnums(num1,num2:integer):integer;stdcall;external 'addnum.dll' name 'addm'{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    var
      zs1,zs2,sum:integer;
    begin
      zs1:=strtoint(edit1.Text);
      zs2:=strtoint(edit2.Text);
      sum:=addnums(zs1,zs2); //调用求和函数计算结果,无法引用别名'addm'
      edit3.Text:=inttostr(sum);
    end;end.
      

  2.   

    发dll好些,声明成stdcall,不要传入成返回string或object
      

  3.   

    可能我没说清楚,实际上我要把a函数做成dll传给客户,但a函数调用了b函数,这个b函数需要客户根据情况临时写,然后客户调用a函数就可以实现完整的功能了
    因为有个没有实现的b函数,所以我不知道如何做成dll
      

  4.   

    a函数的参数里加个b函数的回调参数不就行了么?
    客户调用a函数的时候把客户自己写的b函数当成参数传递给a函数就行了。
      

  5.   


    type
      TfuncB = function(X: Integer): Integer; stdcall;function A(n1, n2, n3: Integer; FuncB: TfuncB): Integer; stdcall;
    begin
      ...
      blah := FuncB(...);
      ...
    end;在dll中导出,把文档写清楚了,使用者自然就知道该怎么用了