我有一个MDIForm的主窗体,调用一个有Form的的Dll,我想把DLL中的Form放在主窗体的Panel中,即有嵌入效果.我将此Form的parent设为MDIForm的Panel(当然中间有句柄传递,不用多说),虽然能够实现嵌入,但子Form上面的控件看不见了.请赐教!

解决方案 »

  1.   

    这样的还是MDI程序么??干脆不要MDI结构好了
      

  2.   

    问题一定出在控件的Paint事件上,在Dll中发布重画窗体的方法,然后在主程序中调用该方法。
      

  3.   

    我也碰到这个问题,不过我连DLL中form也不能显示
      

  4.   

    我贴上代码大家一起研究:DLL上的代码:
    --------------------------------------
    function LoadModal(const AParentCom:TWinControl):integer;stdcall;
    begin
       try
          if not assigned(MainFrm) then
          begin
             MainFrm := TMainFrm.Create(AParentCom);
             MainFrm.Parent := AParentCom;
          end;
          MainFrm.Show ;
          MainFrm.BringToFront ;
       except
          Result := contResErrSys;
          exit;
       end;
       Result := contResOK;
    end;
    原计划嵌入在application上的一个panel里,不过DLL中的窗体只闪了一下就消失,程序运行没有错误提示。
    而且我在DLL调试中确定送入的AParentCom没有问题,因为调试的时候可以正确的读入AParentCom.Name
      

  5.   

    真的是菩萨保佑啊,我们有救啦!下面是我求菩萨求回来的解救代码。
    ============================================================
    library FormDLL;uses
      SysUtils,
      Classes,
      Controls,
      FormInDll in 'FormInDll.pas' {frmFormInDll};{$R *.RES}exports
       Create_FormInDllAsChild,
       Free_FormInDllAsChild ;
    begin
    end.
    unit FormInDll;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;type
      TfrmFormInDll = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      protected
        procedure CreateParams(var Params: TCreateParams); override;
        procedure Loaded; override;
      public
        { Public declarations }
      end;var
      frmFormInDll: TfrmFormInDll = nil;    
      
    procedure Create_FormInDllAsChild(AParent: TWinControl);
    procedure Free_FormInDllAsChild;
    implementation{$R *.DFM}(*----------------------------------------------------------------------------------*)
    procedure Create_FormInDllAsChild(AParent: TWinControl);
    begin
      if not Assigned(frmFormInDll) then
      begin
        frmFormInDll := TfrmFormInDll.CreateParented(AParent.Handle);
        frmFormInDll.Show;
      end;
    end;
    (*----------------------------------------------------------------------------------*)
    procedure Free_FormInDllAsChild;
    begin
      if Assigned(frmFormInDll) then
      begin
        frmFormInDll.Release;
        frmFormInDll := nil;
      end;
    end;
    (*----------------------------------------------------------------------------------*)
    procedure TfrmFormInDll.CreateParams(var Params: TCreateParams);
    begin
      inherited CreateParams(Params);
      Params.Style := Params.Style or WS_CHILD;
    end;
    (*----------------------------------------------------------------------------------*)
    procedure TfrmFormInDll.Loaded;
    begin
      inherited;
      Align       := alClient;
      BorderStyle := bsNone;
      BorderIcons := [];
      Position    := poDefault;
    end;
    (*----------------------------------------------------------------------------------*)
    procedure TfrmFormInDll.Button1Click(Sender: TObject);
    begin
      ShowMessage('Form in a dll created as child to a panel')
    end;end.
    ============================================================Create a new project (New Application) and code its form
    to look like the following form unit============================================================
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      ExtCtrls, StdCtrls;type
      TForm1 = class(TForm)
        Panel1: TPanel;
        Button1: TButton;
        Button2: TButton;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
    implementation{$R *.DFM}procedure Create_FormInDllAsChild(AParent: TWinControl); external 'FormDLL.dll';
    procedure Free_FormInDllAsChild; external 'FormDLL.dll';(*----------------------------------------------------------------------------------*)
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      Create_FormInDllAsChild(Panel1);
    end;
    (*----------------------------------------------------------------------------------*)
    procedure TForm1.Button2Click(Sender: TObject);
    begin
      Free_FormInDllAsChild;
    end;end.============================================================
      

  6.   

    不过我现在发现另外一个问题,就是DLL中的窗体内全部组件对Tab无效。郁闷中。