【发布时间】:2020-04-06 08:22:15
【问题描述】:
我将 C++Builder 10.3 与适用于 Windows 的 VCL 应用程序一起使用。我试图通过遍历项目标题并使用 CompareText() 将标题与我的搜索文本进行比较来识别 AdvPopupMenu 中的特定项目。字幕在字幕文本中有一个“&”,我认为这是快捷方式功能的一部分。在比较文本时,这似乎可以防止匹配。
我尝试了两种设置菜单项的方法来尝试删除“&”。
//--#1 Menu Setup--
TMenuItem *NewMenuItem;
NewMenuItem = new TMenuItem(MainForm->AdvPopupMenu1);
TShortCut sc2;
sc2 = TextToShortCut("(None)");
NewMenuItem->Caption = "Google";
NewMenuItem->ShortCut = sc2;
//--#2 Menu Setup--
TMenuItem *NewMenuItem;
NewMenuItem = new TMenuItem(MainForm->AdvPopupMenu1);
NewMenuItem->Caption = "Google";
NewMenuItem->ShortCut = NULL;
下面是我搜索 AdvPopupMenu 项的循环。
UnicodeString SearchFor = "Google";
UnicodeString TestCaption;
for(int i=0; i<MainForm->AdvPopupMenu1->Items->Count; i++){
TestCaption= MainForm->AdvPopupMenu1->Items->Items[i]->Caption;
if(CompareText(SearchFor , TestCaption)==0 ){
//This CompareText always fails
//TestCaption looks like this "&Google" or this "G&oogle"
}
}
如何将 AdvPopupMenu Caption 设置为不包含“&”并使 CompareText 工作?
【问题讨论】:
标签: delphi c++builder