如何在c++builder中更改TMenuItem的可见性

How to change visibility of TMenuItem in c++ builder?

本文关键字:TMenuItem 可见性 c++builder      更新时间:2023-10-16

我正在使用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";
 }

我认为它应该起作用,但我总是遇到应用程序崩溃的情况。带有这种信息:

调试器异常通知项目Project1.exe在地址处引发了异常类EAccessViolation,消息为Access违规模块vcl120.bpl中的501C380E。读取地址0000003C

任何帮助都将不胜感激。

TMenu具有类型的属性

_property TMenuItem* Items

其又具有阵列型的特性

__property TMenuItem* Items[int Index]

因此,解决方案是(正如n.m.已经注意到的那样)编写

TMenuItem* tmpAction = MainMenu1->Items->Items[i];