我用dll建立了一个窗体,怎么与之里面的控件通讯?

解决方案 »

  1.   

    你的DLL是有模式窗体还是无模式窗体!
      

  2.   

    不知道,你想干什么,不过我知道你这样的想法基本是错误的,这样不符合模块封装的原理,你就不应该去访问DLL里的东西。你应该是在DLL中提供一个方法让EXE去调用从而达到改变或读取组件的状态。不过你要作到这一点也很Easy
      

  3.   

    主调单元:
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, DLLUnit;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
        procedure FormCreate(Sender: TObject);
        procedure FormDestroy(Sender: TObject);
      private
        { Private declarations }
        FDLLForm: TDllForm;
      public
        { Public declarations }
      end;var
      Form1: TForm1;function ExportForm: Integer;  external 'DLL.dll';
    procedure FreeForm; external 'DLL.dll';
    implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    begin
      FDLLForm.Edit1.Text := 'abc';
      FDLLForm.Show;
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      FDLLForm := TDllForm(ExportForm);
    end;procedure TForm1.FormDestroy(Sender: TObject);
    begin
      FreeForm;
    end;end.
      

  4.   

    被调单元:
    unit DLLUnit;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TDllForm = class(TForm)
        Edit1: TEdit;
      private
        { Private declarations }
      public
        { Public declarations }
      end;implementation{$R *.dfm}var
      DllForm: TDllForm;function ExportForm: Integer;
    begin
      if DllForm = nil then
        DllForm := TDllForm.Create(nil);
      Result := Integer(DllForm);
    end;procedure FreeForm;
    begin
      if DllForm <> nil then
        FreeAndNil(DllForm);
    end;exports
      ExportForm,FreeForm;end.