RT

解决方案 »

  1.   

    再补充下:就是我想在DLL文件中处理我取到的控件。不是在应用程序中取。因为有FindControl函数可以使用。在这里我想通过DLL来处理。
    如果知道的就请告诉,谢谢!
      

  2.   

    //下面为DLL
    library findCtrl;
    uses
      SysUtils,
      Classes,
      Unit1 in 'Unit1.pas';{$R *.res}
      exports
        GetString,
        FindCtrol;
    begin
    end.
    //DLL的单元
    unit Unit1;
    interface
      uses
        Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
        Dialogs, StdCtrls;  function FindCtrol(handle: THandle): TWinControl; stdcall;
    implementationfunction FindCtrol(handle: THandle): TWinControl; stdcall;
    begin
      Result := FindControl(handle);
    end;
    end.//下面为调用DLL
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TFindCtrol = function (handle: THandle): TWinControl; stdcall;
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    var
      myFindCtrol: TFindCtrol;
      Ctrol: TWinControl;
      Hwd: Cardinal;
    begin
      Hwd := LoadLibrary(Pchar('F:\Dll\findCtrl.dll'));
      try
        if Hwd <> 0 then
        begin
          myFindCtrol := GetProcAddress(Hwd, Pchar('FindCtrol'));
          if @myFindCtrol <> nil then
            Ctrol := myFindCtrol(Button1.Handle);
        end;
        if Ctrol <> nil then
          ShowMessage(Ctrol.Name);
      finally
        if Hwd <> 0 then
          FreeLibrary(Hwd);
      end;
    end;end.
    //记住每个工程里面都得调用 vcl这个运行包. 把每个工程的 build with runtime packages 勾上就可以了.