通過DLL中的導出函數CallDLLFormByTag調出DLL中窗體來,但不知如何設置使其變成主窗體的MDI子窗體,
procedure CallDLLFormByTag(a: integer;MainForm: TForm);
begin
  try
    case a of
      1:
      begin
        frmCac := TfrmCac.Create(nil);
        frmCac.ParentWindow := MainForm.Handle;
        frmCac.Show;
      end;
      2:
      begin
        Form1 := TForm1.Create(nil);
        Form1.ParentWindow := MainForm.Handle;
        Form1.Show;    
      end;
      else
      begin
        //
      end;
    end;
  finally
   //
  end;
end;
求解

解决方案 »

  1.   


    Form1 := TForm1.Create(nil);
    //我喜欢这样调用:
    //Application.CreateForm(TForm1, Form1);Form1.FormStyle:=fsMDIChild;
    Form1.ParentWindow := MainForm.Handle;
    Form1.Show; 
      

  2.   

    这样会报错的啊,说不是没有MDI子窗体。
      

  3.   

    要传入主程序的Application到DLL窗体中.前几天用DLL封装子窗体的方式开发困惑了好几天.
      

  4.   

    ----->要传入主程序的Application到DLL窗体中.
    什麼意思 啊?能不能說明一下?
      

  5.   

    procedure CallDLLFormByTag(a: integer;AHandle: THandle);
    begin
      Application.Handle:=aHandle;
      try
        case a of
          1:
          begin
            frmCac := TfrmCac.Create(Application);
            frmCac.ParentWindow := aHandle;
            frmCac.Show;
          end;
          2:
          begin
            Form1 := TForm1.Create(Application);
            Form1.ParentWindow :=aHandle;
            Form1.Show;    
          end;
    在mainform掉用的时候,把mainform.handel出入到ahandle参数看看,
      

  6.   

    黨員同志,這樣是可以的,但是不是MDI窗體啊,我要從DLL中調出的窗體加入到主窗體中,變成MDI子窗體。
      

  7.   

    加上这个也不行吗?
    frmCac.FormStyle:=fsMDIChild;
      

  8.   

    如果不是從DLL中調出一個窗體,加上frmCac.FormStyle:=fsMDIChild;
    是可以的, 但是在調用DLL的窗體就會出錯:no MDI forms  are currently actived
      

  9.   

    我DLL中的引用單元:
    unit ExportUnit;
    interface
    implementation
    uses
      SysUtils, Classes,  Forms,
        test  ,   test2   ;procedure ShowDLLMDIForm(a: integer;AHandel : THandle);
    begin
      Form1 := TForm1.Create(nil);
      Form1.FormStyle:=fsMDIChild;
      Form1.ParentWindow :=AHandel;
      Form1.Show;end;exports ShowDLLMDIForm;
    //-----------------
    end.
      

  10.   

    procedure CallDLLFormByTag(a: integer;AHandle: THandle);
    begin
      Application.Handle:=aHandle;
      try
        case a of
          1:
          begin
            frmCac := TfrmCac.CreatePanerted(Application.MainForm.Handle);
            frmCac.Show;
          end;
     ……   
          end;
    在看看吧,同志,,,
      

  11.   

    我傳出APPlication.handle進去,如你寫的還是不行啊。同志,有無其它的設置呢??
      

  12.   

    动态调用Dll中的MDI子窗体,从一个例子中摘抄的,供参考:type
      InvokeDLLForm = function(App: TApplication; Scr: TScreen): TForm;procedure TfrmMain.mi_inDLLClick(Sender: TObject);
    var
      DLLHandle: THandle;
      DLLSub: InvokeDLLForm;begin
      DLLHandle := LoadLibrary('prjDLL.dll');
      if DLLHandle <> 0 then
      begin
        @DLLSub := GetProcAddress(DLLHandle, 'CreateDLLForm');
        if Assigned(DLLSub) then
        begin
          DLLForm := DLLSub(Application, Screen);
        end;
      end;
    end;--Dll中的Dpr文件---------------------------
    library prjDLL;{ 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,
      Forms,
      Windows,
      Messages,
      Classes,
      DLLFormUnit in 'DLLFormUnit.pas' {frmDLLForm},
      AboutUnit in 'AboutUnit.pas' {frmAbout};{$R *.res}var
      DLLApp: TApplication;
      DLLScr: TScreen;
    function CreateDLLForm(App: TApplication; Scr: TScreen):TForm;
    var
      ptr:PLongInt;
    begin
      Application := App;
      Screen := Scr;
      Application.CreateForm(TfrmDLLForm, frmDLLForm);
      Application.CreateForm(TfrmAbout, frmAbout);
      result:=frmDLLForm;
    end;procedure ExitDLL(Reason: Integer);
    begin
      if Reason = DLL_PROCESS_DETACH then
      begin
        Application := DLLApp;
        Screen := DLLScr;
      end;
    end;
    exports
      CreateDLLForm;begin
      DLLApp := Application;
      DLLScr := Screen;
      DLLProc := @ExitDLL;end.------------------------------------网上有完整的例子,可以去搜一下。
      

  13.   

    我找到了,謝樓上
    procedure ShowDLLMDIForm(ParentApplication: TApplication; ParentForm: TForm);export; stdcall;
    begin
    Application:=ParentApplication;
    Form1:=TForm1.Create(ParentForm); 
    Form1.Show;
    end;
    //-----------------
    library dllFinanceRep;{ 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,  Windows, Messages, Forms,
      test in 'test.pas' {Form1},
      test2 in 'test2.pas' {Form2},
      ExportUnit in 'ExportUnit.pas';
      
    var
      DllApplication: TApplication;
    procedure DLLUnloadProc(Reason: Integer); register;
    begin
      if Reason = DLL_PROCESS_DETACH
        then Application:=DllApplication;
    end;{$R *.res}
    begin
      DllApplication:=Application;
      DLLProc := @DLLUnloadProc;
    end.