假如我现在在DLL文件中建立了一个窗体,上面放了个edit1和button1控件,另建立了个主窗体,上面也放了个edit1和button1控件。我想在主窗体上点击button控件调出dll文件中的窗体,在dll的窗体的edit1中输入数据,点DLL窗体上面的button控件,输入的数据怎样才能添加到主窗体的edit中。谢谢了,分数不够可以再给。

解决方案 »

  1.   

    主Form的Edit作为参数传给DLL中Form就OK了。可以给分了。
      

  2.   

    第一个问题:
      用setfocus;
    第二个问题:
      发送消息吧
      

  3.   

    dll文件内容如下
    uses
      SysUtils,
      Classes,
      forms,
      Unit1 in 'Unit1.pas' {fm_main};{$R *.res}function ShowMainForm(AHandle: THandle;ACaption:PChar): Longint; stdcall;
    begin
      Application.Handle := AHandle;
      fm_Main := Tfm_Main.Create(nil);
      fm_Main.Caption:=ACaption
      Result := Longint(fm_Main);
      fm_Main.Show;
    end;exports
      ShowMainForm;
    end.主调窗体如下:
    var
      Form1: TForm1;implementation
    function ShowMainForm(AHandle: THandle;ACaption:PChar;bCaption:PChar): Longint;   stdcall; external 'about.dll';
    {$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    begin
     ShowMainForm(application.handle,pchar(edit1.text),pchar(edit2.text));end;
      

  4.   

    library Project1;{ 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,
      Unit1 in 'Unit1.pas' {Form1};{$R *.RES}function Returnstr:string;stdcall;
    begin
      with TForm1.Create(nil) do
      try
        showmodal;
        Result := trim(edit1.text);
      finally
        free;
      end;
    end;exports
      Returnstr;begin
    end.
    这是dll的代码。
    procedure TForm1.Button1Click(Sender: TObject);
    var
      DllHandle : THandle=0;
      Rd : function : String; stdcall;
    begin
      DllHandle := LoadLibrary('mydll.dll');
      if DllHandle > 0 then
        @Rd := GetProcAddress(DllHandle,'ShowMainForm')
      else
      begin
        DllHandle := 0;
        @Rd := nil;
      end;  if (DllHandle > 0) and (@Rd <> nil) then
        edit1.text := Rd
      else
        edit1.text := '';
    end;
    这是调用的代码。你看看。
      

  5.   

    楼上的例子,我都试了。不过还是运行通不过,“回复人: hhnick(nick) ( ) 信誉:100 ”的例子里,单击button时DLL文件中的窗体没出现,以后的就没法操作了。不过还是谢谢各位朋友了,继续寻求答案