100分求Delphi主窗体调用 Dll下的子Frame或form也就是将Form或frame封裝成dll供主窗體調用,关键是将这个form或frame加入到主窗体的pagecontrol中去,
這是一个经典而又古老的问题,很少有人知能真正解决,真是无奈......最好是有源碼,不要只言片语,如果哥哥你只给一部分代码还是算了。
非常感谢,
Mail:[email protected]
   

解决方案 »

  1.   

    DLL代码,TForm2是dll中加的一个窗体,你自己随便加一个就行library Project1;uses
      SysUtils,
      Classes,
      Controls,
      Forms,
      Windows,
      Unit2 in 'Unit2.pas' {Form2};{$R *.res}
    procedure ShowForm(parent:THandle);stdcall;
    var
      frm : TForm2;
    begin
      frm := TForm2.Create(Application);
      frm.ParentWindow := parent;
      frm.Show;
      frm.Align := alClient;
    end;exports
      ShowForm name 'ShowForm';beginend.
    调用,传入Panel1的句柄
    procedure ShowForm(parent:THandle);stdcall;external 'Project1.dll';procedure TForm1.Button1Click(Sender: TObject);
    begin
      ShowForm(Panel1.Handle);
    end;
      

  2.   

    如果显示在pagecontrol中的话,就这样写
    ShowForm(PageControl1.Pages[0].Handle);
      

  3.   

    测试一直提示:无法找到函数的入口:下面我给出按照你上面的代码,:
    ------------------------------------------------------
    DLL部分:
    -------
    library UDllFrom;{ 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,
      forms,
      controls,
      UChildForm in 'UChildForm.pas' {childForm};{$R *.res}procedure run_form(parent:THandle);stdcall;
    var
     childForm: TchildForm;
     begin
       childForm:=TchildForm.Create(Application);
       childForm.ParentWindow:=parent;
       childForm.Show;
       childForm.Align:=alclient;
     end;
     exports
      run_form name 'run_form';
    begin
    end.
    -------------------------------------------------------
    调用:
    -------
    unit UTestForm;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, RzTabs, StdCtrls, Buttons, Menus, ExtCtrls;type
      TTestForm = class(TForm)
        rzpgc: TRzPageControl;
        tbs: TRzTabSheet;
        Panel1: TPanel;
        MainMenu1: TMainMenu;
        test1: TMenuItem;
        procedure test1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
     procedure rum_Form(parent:THandle);stdcall;external 'UDllFrom.dll';
    var
      TestForm: TTestForm;implementation{$R *.dfm}procedure TTestForm.test1Click(Sender: TObject);
    begin
      rum_Form(Panel1.Handle);
    end;end.
    --------------------------------
    一直接提示错误
      

  4.   

    --------我给出我自已的调用,帮我看看吗?也是找不到DLL的入口处
    library UDllFrom; //DLL庫封裝之處{ 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,
      forms,
      RzTabs,
      UChildForm in 'UChildForm.pas' {Form1};{$R *.res}
     procedure AddTabSheet(FormClass: TFormClass;tbs:TRZTabSheet; rzpgc:TRZPagecontrol);
     var
     Form:TForm;
    begin
      rzpgc.ActivePage := tbs;     //加上这一步算是双向指定了,指定激活页
      Form := FormClass.Create(tbs);    //创建Form(用TabSheet)实例
      Form.Parent := tbs;           //指定Form的父窗体
      tbs.Caption := Form.Caption;   //标题
      tbs.TabVisible:=True;
      Form.Show;   //显示
    end;
    function run_form(hs:THandle;tbs:TRZTabSheet;rzpgc:TRZPagecontrol):integer;stdcall;
    var
     TForm1:TFormclass;
     begin
       Application.Handle:=hs;
       AddTabSheet(TForm1,tbs,rzpgc);
     end;
     exports
      run_form;
    begin
    end.
    -----------------------------調用DLL窗體,將子窗体装入主窗体中
    unit UTestForm;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, RzTabs, StdCtrls, Buttons;type
      TTestForm = class(TForm)
        rzpgc: TRzPageControl;
        tbs: TRzTabSheet;
        BitBtn1: TBitBtn;
        procedure BitBtn1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
      function rum_Form(hs:THandle;tbs:TRZTabSheet;rzpgc:TRZPagecontrol):Integer;stdcall;external 'UDllFrom.dll';
    var
      TestForm: TTestForm;implementation{$R *.dfm}procedure TTestForm.BitBtn1Click(Sender: TObject);
    begin
       rum_Form(Application.Handle,tbs,rzpgc);
    end;end.
    ----------------------------
    提示錯誤,無法找到程序的輸入點