我自己从TPageControl上继承写了个PageControl控件,定义为TLCPageControl
又从TTabSheet继承写了个TLCTabSheet
现想TLCPageControl能动态的生成TLCTabSheet
可我现在动态生成TLCTabSheet就死机,应该是机制没明白,有知道的吗?不胜感激!

解决方案 »

  1.   

    http://yya.nease.net/Delphi/D00041.html
    动态创建PageControl和TabSheet
     
    更新日期:2004-03-19 
     
    var
    T : TTabSheet;
    P : TPageControl;
    begin
    // Create the PageControl
    // need to reference the page control so we need a reference to it.P := TPageControl.Create(application);
    with P do begin
    Parent := Form1; // set how controls it.
    Top := 30;
    Left := 30;
    Width := 200;
    Height := 150;
    end; // with TPageControl// Create 3 pages
    T := TTabSheet.Create(P);
    with T do begin
    Visible := True; // This is necessary or form does not repaint 
    // correctly
    Caption := 'Page 1';
    PageControl := P; // Assign Tab to Page Control
    end; // withT := TTabSheet.Create(P);
    with T do begin
    Visible := True; // This is necessary or form does not repaint 
    // correctly
    Caption := 'Page 2';
    PageControl := P; // Assign Tab to Page Control
    end; // withT := TTabSheet.Create(P);
    with T do begin
    Visible := True; // This is necessary or form does not repaint 
    // correctly
    Caption := 'Page 3';
    PageControl := P; // Assign Tab to Page Controlend; // with// Create 3 buttons, 1 per page
    with tbutton.create(application) do begin
    Parent := P.Pages[0]; // Tell which page owns the Button
    Caption := 'Hello Page 1';
    Left := 0;
    Top := 0;
    end; // withwith tbutton.create(application) do begin
    Parent := P.Pages[1]; // Tell which page owns the Button
    Caption := 'Hello Page 2';
    Left := 50;
    Top := 50;
    end; // withwith tbutton.create(application) do beginParent := P.Pages[2]; // Tell which page owns the Button
    Caption := 'Hello Page 3';
    Left := 100;
    Top := 90;
    end; // with// This needs to be done or the Tab does not sync to the 
    // correct page, initially. Only if you have more then 
    // one page.
    P.ActivePage := P.Pages[1];
    P.ActivePage := P.Pages[0]; // page to really show 
    end;
      

  2.   

    to  aiirii(ari-爱的眼睛) 
    我的PageControl和TabSheet都是我自己写的分别为TLCPageControl和TLCTabSheet
      

  3.   

    var TMySheet:TLCTabSheet;
    TMySheet := TLCTabSheet.Create (self);
    TMySheet.PageControl :=TLCPageControl;