我想问问,你怎么实现扫描呢?
如果要此dll可以通用的话,传递它的handle好了。
另,看看你是否在dll中use了forms

解决方案 »

  1.   

    HANNDLE传过去以后,怎么用???没办法通过HANDLE使用FORM的属性呀
      

  2.   

    哦,你误会了。
    我的意思是如果要使dll可以通用,那么只能传递句柄之类的东西。
    不清楚你的“扫描”,是遍历form上所有的控件吗
      

  3.   

    delphi会自动生成这句话
    Unit1 in 'Unit1.pas' {Form1};
    然后你就可以用了
      

  4.   

    DELPHI怎样自动生成???我传递给DLL一个句柄,在DLL中怎样使用这个句柄????
      

  5.   

    给你个例子吧一.函数过程的写法:
    library FIRSTDLL;
    uses   SysUtils, Classes;
    {$R *.RES}
    // 1.定义函数具体过程和输出接口方式   // 函数 1    // 功能:事数据3倍放大函数
    function PenniesToSoins(SourceResult:Integer):Integer;stdCall;
    begin
     if SourceResult>0 then
       Result:=SourceResult*3 //结果存放于Result
     else
       Result:=SourceResult;
    end;
    exports 
     PenniesToSoins; //2.函数输出口定义
    end.
    二.在DLL中创建Form
    1.一步,创建DLL工程,及加入设置好的Form
    library MGRPERSN;
    uses   SysUtils, Classes,
     MGRPERFM in 'MGRPERFM.pas' {FormPERSON};//1.Form的代码(与一般的Form一样)
    {$R *.RES}
    exports
      ShowPerSN;//2.函数输出口定义
    begin
    end.
    2. 在DLL设定的Form的设置 
    unit MGRPERFM;
    interface
    uses  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
     ComCtrls, ToolWin, ImgList;
    type
     TFormPERSON = class(TForm)
     private
       { Private declarations }
     public
       { Public declarations }
     end;
    //些处的变量不再用,给其改个地方,如下(改变之一)
    //var  FormPERSON: TFormPERSON;
    { Declare the export function 宣布Form函数出口}//改变之二
    function ShowPerSN(AHandle: THandle; ACaption: String):BOOL; StdCall;
    implementation
    {$R *.DFM}   //函数据过程定义
    function ShowPerSN(AHandle: THandle; ACaption: String):BOOL;
    var   FormPERSON: TFormPERSON; //定义窗体类(上面的放到了此处)
    begin
    //拷贝应用程式句柄给DLL的应有程式对象
     Application.Handle := AHandle;
     FormPERSON := TFormPERSON.Create(Application);//创建控件TForm
     try
       FormPERSON.Caption := ACaption;
       FormPERSON.ShowModal;//显示此Form      
       Result := False; //反回成功值
     finally
       FormPERSON.Free;
     end;
    end;
    三.DLL中函数及窗体的调用
    1.调用方法一
    implementation //在此的下方写明调用函数的DLL
    {$R *.DFM}//DLL内函数调用
    function PenniesToSoins(SourceResult:Integer):Integer;  StdCall external 'FIRSTDLL.DLL';
    2.调用方法二
    type  //在此创建一个函数类
    { First, define a procedural data type, this should reflect the procedure that is exported from the DLL. }
     { Create a new exception class to reflect a failed DLL load }
     TShowPerSN = function (AHandle: THandle; ACaption: String): BOOL; StdCall;
     EDLLLoadError = class(Exception);//同时创建一个出错记录类
    TMAINCLTR = class(TForm) //这里不变,系统自动生成
    procedure TMAINCLTR.ToolButton1Click(Sender: TObject);
    var  //按钮的调用事件:调用过程
     LibHandle: THandle;   ShowPerSN: TShowPerSN;
    begin
     Application.Title:='人力资源管理系统DLL文件测试程式';
     LibHandle := LoadLibrary('MGRPERSN.DLL'); { Attempt to load the DLL 尝试装入DLL文件}
     try
       if LibHandle = 0 then
         raise EDLLLoadError.Create('Unable to Load DLL(无法成功装入MGRPERSN.DLL)');
       @ShowPerSN := GetProcAddress(LibHandle, 'ShowPerSN');
       if not (@ShowPerSN = nil)  then  ShowPerSN(Application.Handle, '人事资料管理')//呼叫出窗体
       else     RaiseLastWin32Error;
     finally
       FreeLibrary(LibHandle); // Unload the DLL.
     end;
    end;
      

  6.   

    同意楼上的
    我有一个分布式的系统,包含很多的工程在系统中
    有跟多的模块很类似
    我就是把这些类似的东西定义在一个DLL中的
    做法么? 先和做普通的工程一样
    完成以后只要把Project该为Liblary然后定义好export就可以调用了!
      

  7.   

    我是想通过主窗体FORM1调用DLL ,同时将主窗体的HANDLE传递给DLL,该DLL
    的功能是修改主窗体控件属性。谢谢大家了,我还是不太会
      

  8.   

    可以试试:
    ----------------------
    1. 使用WINDOWS消息机制通过发送消息实现DLL和窗体间的通讯
    2. 在程序中编写两个过程,一个用于读取窗体属性,另一个用于修改窗体属性,
       装载DLL时将这两个过程作为参数传递到DLL中,形成回叫
    3. 使用WINDOWS API