我正在使用 C++ Builder 开发应用程序。 我想遍历 MainMenu 中的所有 TMenuItems,因为我想更改其中一些的标题。 我使用了这段代码:
int numAction = MainMenu1->Items->Count;
for (int i=0;i<numAction;i++)
{
TMenuItem* tmpAction = &MainMenu1->Items[i];
tmpAction->Caption = "Test Caption";
}
我认为它应该可以工作,但我总是遇到应用程序崩溃的问题。有了这种消息:
Debugger Exception Notification Project Project1.exe raised exception class EAccessViolation with message Access violation at address 501C380E in module vcl120.bpl. Read of address 0000003C.
我们将不胜感激。
最佳答案
TMenu
有一个类型的属性
_property TMenuItem* Items
依次有一个数组类型的属性
__property TMenuItem* Items[int Index]
所以,解决方案是(正如 n.m. 已经注意到的那样)写
TMenuItem* tmpAction = MainMenu1->Items->Items[i];
关于c++ - 如何更改 C++ 构建器中 TMenuItem 的可见性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33474801/