if FindComponent('cx'+tempName)<>nil then begin ShowMessage('find'); end; for I := 0 to ComponentCount-1 do begin if (Components[i] is TcxTabSheet) then if TcxTabSheet(Components[i]).Name=('cx'+tempName) then begin ShowMessage('find'); end; end; 行不通,找不到
准确说 if (Components[i] is TcxTabSheet) then这句都找不到
如果要用FindComponent 要递归。 begin //不存在则新建一个TcxTabSheet try tempSheet:=TcxTabSheet.Create(MainPG); with tempSheet do begin AllowCloseButton:=True; Caption:=tempName; Enabled:=True; Name:='cx'+tempName; Visible:=True; Parent:=MainPG; ParentWindow:=MainPG.Handle; TabVisible:=True; end; tabSheetList.Add(tempSheet.Name); Result:=tempSheet; MainPG.ActivePage:=tempSheet; finally end; end;少写了: tempSheet.PageControl := MainPG;
根据你的思路,想了个挫办法。 for i := 0 to MainPG.PageCount-1 do begin if MainPG.Pages[i].Name=('cx'+tempName) then begin MainPG.ActivePage:=MainPG.Pages[i]; Result:=MainPG.Pages[i]; ShowMessage('find'); end; end;
PageControl1.ActivePage := TTabSheet(Self.FindComponent('TabSheet2'));
Tpagecontrol.pages里有它们的列表
if FindComponent('cx'+tempName)<>nil then
begin
ShowMessage('find');
end; for I := 0 to ComponentCount-1 do
begin
if (Components[i] is TcxTabSheet) then
if TcxTabSheet(Components[i]).Name=('cx'+tempName) then
begin
ShowMessage('find');
end;
end;
行不通,找不到
准确说
if (Components[i] is TcxTabSheet) then这句都找不到
begin
//不存在则新建一个TcxTabSheet
try
tempSheet:=TcxTabSheet.Create(MainPG);
with tempSheet do
begin
AllowCloseButton:=True;
Caption:=tempName;
Enabled:=True;
Name:='cx'+tempName;
Visible:=True;
Parent:=MainPG;
ParentWindow:=MainPG.Handle;
TabVisible:=True;
end;
tabSheetList.Add(tempSheet.Name);
Result:=tempSheet;
MainPG.ActivePage:=tempSheet;
finally
end;
end;少写了: tempSheet.PageControl := MainPG;
begin
if MainPG.Pages[i].Name=('cx'+tempName) then
begin
MainPG.ActivePage:=MainPG.Pages[i];
Result:=MainPG.Pages[i];
ShowMessage('find');
end;
end;