delphi TcxPageControl 动态嵌入窗体

type
  TMyForm_test = class(TForm)
    cxpgcntrl1: TcxPageControl;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

type
  Applicationclass = class(TObject)
    class procedure addforms(Form: TForm);
    class function returnTcxPageControl: TcxPageControl;
    class procedure addMDIChild(MDIChildFormClass: TFormClass; var Reference; MenuName: string; midform: TFormClass);
  end;

var
  MyForm_test: TMyForm_test;

implementation

uses
  UnitTest123;

{$R *.dfm}

procedure TMyForm_test.FormCreate(Sender: TObject);
var
  temp: TFormTest123;
begin
  temp := TFormTest123.Create(nil);
  temp.Caption := '测试下';
  Applicationclass.addMDIChild(TFormTest123,temp,temp.Caption,TFormTest123);
end;

class procedure Applicationclass.addforms(Form: TForm);
var
  Sheet: TCXTabSheet;
begin
  Sheet := TCXTabSheet.Create(returnTcxPageControl);
  Sheet.font.size := 14;
  Sheet.font.Name := 'MS Sans Serif';
  Sheet.font.Style := [];
  Sheet.caption := Form.caption;
  Sheet.handles := Form.Handle;
  Sheet.Pform := Form;
  Sheet.PageControl := returnTcxPageControl;
  Sheet.ImageIndex := 0;
  Sheet.Tag := 2;
  Form.Parent := Sheet;
  Applicationclass.returnTcxPageControl.activePage := Sheet;
end;

class function Applicationclass.returnTcxPageControl: TcxPageControl;
begin
  result := MyForm_test.cxpgcntrl1;
end;

class procedure Applicationclass.addMDIChild(MDIChildFormClass: TFormClass; var Reference; MenuName: string; midform: TFormClass);
var
  MDIChildForm: TForm;
  I: Integer;
  WHandle: HWnd;
  Step: Integer;
begin
  with Application.MainForm do
  begin
    LockWindowUpdate(GetDeskTopWindow);
    try
      Screen.Cursor := crHourglass;
    except
      LockWindowUpdate(0);
      Screen.Cursor := crDefault;
      Application.ShowException(Exception(ExceptObject));
      Abort;
    end;
    try
      MDIChildForm := TForm(Reference);
      MDIChildForm.Parent := returnTcxPageControl;
      MDIChildForm.WindowState := wsMaximized;

      MDIChildForm.BorderIcons := [biMinimize, biMaximize];
      Applicationclass.addforms(MDIChildForm);
      MDIChildForm.Visible := true;
    finally
      Screen.Cursor := crDefault;
      LockWindowUpdate(0);
    end;
  end;
end;