var
TS:TTabSheet;
begin
TS := TTabSheet.Create(Self);
TS.PageControl := PC;
TS.Name := 'TS1';
TS.Caption := 'TS1';
end;如果是多个TabSheet,只要TS.Name设置成不同就可以了。
TS:TTabSheet;
begin
TS := TTabSheet.Create(Self);
TS.PageControl := PC;
TS.Name := 'TS1';
TS.Caption := 'TS1';
end;如果是多个TabSheet,只要TS.Name设置成不同就可以了。
如果有多个,可用
for i:=0 to n do
begin
TS := TTabSheet.Create(Self);
TS.PageControl := PC;
TS.Name := 'TS'+inttostr(i);
TS.Caption := 'TS'+inttostr(i) ;
end;
提示为:Control '' has no parent window
估计是你调用的时候有问题。是在一个Form的函数中创建的么?最简单的程序:
新建一个Form,放一个PC:TPageControl;
在FormCreate中,动态增加一个TabSheet。
win2000+D6运行通过。unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls;type
TForm1 = class(TForm)
PC: TPageControl;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
var
TS:TTabSheet;
begin
TS := TTabSheet.Create(Self);
TS.PageControl := PC;
TS.Name := 'TS1';
TS.Caption := 'TS1';
end;end.
是做元件时出错,不是在Form上建立。