怎么找到已经存在的标签页
如何找到已经存在的标签页
------解决方案--------------------
用FOR循环遍历,比较每个标签页标题和目标字符串
------解决方案--------------------
if Self.FindComponent('TabSheet2') <> nil then
PageControl1.ActivePage := TTabSheet(Self.FindComponent('TabSheet2'));
------解决方案--------------------
TcxTabSheet应该在Tpagecontrol里吧
Tpagecontrol.pages里有它们的列表
------解决方案--------------------
如果要用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;
tabSheetList:TStringList;
function TbsMainForm.GetTabSheet(tabName: string): TcxTabSheet;
var tempSheet:TcxTabSheet;
tempName:string;
tempDirName:string;
begin
Result:=nil;
if tabName='' then
begin
Exit;
end;
tempDirName:=ExtractFileDir(ParamStr(0));
tempName:=StringReplace(tabName,tempDirName+'\','',[rfReplaceAll]);
tempName:=Copy(tempName,1,pos('.',tempName)-1);
if tabSheetList.IndexOf('cx'+tempName)<>-1 then
begin
//存在 则SHOW TcxTabSheet
//如何找到已经存在的对应的 TcxTabSheet(根据.NAME来判断)
tempSheet:=....?????
MainPG.ActivePage:=tempSheet;
end
else
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;
end;
------解决方案--------------------
用FOR循环遍历,比较每个标签页标题和目标字符串
------解决方案--------------------
if Self.FindComponent('TabSheet2') <> nil then
PageControl1.ActivePage := TTabSheet(Self.FindComponent('TabSheet2'));
------解决方案--------------------
TcxTabSheet应该在Tpagecontrol里吧
Tpagecontrol.pages里有它们的列表
------解决方案--------------------
如果要用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;