如何找到已经存在的标签页

thumb0422 2013-11-27 04:36:07

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;
...全文
266 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
hsfzxjy 2013-11-28
  • 打赏
  • 举报
回复
遍历最方便了,findcomponent找的还不是caption。。
thumb0422 2013-11-28
  • 打赏
  • 举报
回复
引用 4 楼 sz_haitao 的回复:
TcxTabSheet应该在Tpagecontrol里吧 Tpagecontrol.pages里有它们的列表
根据你的思路,想了个挫办法。

    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;
Wang-Ping 2013-11-28
  • 打赏
  • 举报
回复
如果要用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;
thumb0422 2013-11-28
  • 打赏
  • 举报
回复
准确说
 if (Components[i] is TcxTabSheet) then
这句都找不到
thumb0422 2013-11-28
  • 打赏
  • 举报
回复
引用 3 楼 yanlei1987 的回复:
if Self.FindComponent('TabSheet2') <> nil then PageControl1.ActivePage := TTabSheet(Self.FindComponent('TabSheet2'));

   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;
行不通,找不到
thumb0422 2013-11-28
  • 打赏
  • 举报
回复
引用 3 楼 yanlei1987 的回复:
if Self.FindComponent('TabSheet2') <> nil then PageControl1.ActivePage := TTabSheet(Self.FindComponent('TabSheet2'));
这样行不通,不知道为什么始终找不到Self.FindComponent('TabSheet2'),而如果去找别的控件比如EDIT 是可以找到的。
haitao 2013-11-28
  • 打赏
  • 举报
回复
TcxTabSheet应该在Tpagecontrol里吧 Tpagecontrol.pages里有它们的列表
RayYan 2013-11-28
  • 打赏
  • 举报
回复
if Self.FindComponent('TabSheet2') <> nil then PageControl1.ActivePage := TTabSheet(Self.FindComponent('TabSheet2'));
thumb0422 2013-11-28
  • 打赏
  • 举报
回复
引用 1 楼 HSFZXJY 的回复:
用FOR循环遍历,比较每个标签页标题和目标字符串
这个虽然是一种方法,但是如果页面上控件比较多的话,遍历不太适合哦。
hsfzxjy 2013-11-27
  • 打赏
  • 举报
回复
用FOR循环遍历,比较每个标签页标题和目标字符串

5,392

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧