我在表单上有弹出菜单控件(grr,我很可能会使它成为动态的-讨厌静态工具)。它有一个子菜单项。子菜单有三个菜单项(TMenuItem类)。
我需要通过在if..then语句中输入Sender param来进行检查,只要有子菜单项或子菜单项调用了过程。
我尝试了不同的字体转换和超类操作,但没有成功。我认为可以这样做:
if FindControl(MenuItemWithSubMenu.Handle) = TControl(Sender as TComponent).Parent then ...
但是,当然,通过正确的打字和命令。。
任何想法都值得赞赏。
按社区要求提供的其他信息:
代码itsef(如果我只是通过组件名prop进行检查)如下所示:
procedure TForm1.xClick(Sender: TObject); // procedure that has attached onClick from PopupActionBar1 Items
begin
if ((TComponent(Sender).Name = 'Unloadresources1') or // PopupActionBar1.Items[3]
(TComponent(Sender).Name = 'VKPCache11') or // PopupActionBar1.Items[3].Items[0]
(TComponent(Sender).Name = 'VKPCache21') or // PopupActionBar1.Items[3].Items[1]
(TComponent(Sender).Name = 'AllCache31') or // PopupActionBar1.Items[3].Items[2]
(ActLoadVal = 2)) and (PopupActionBar1.Items[3].Caption = 'Delete VKP Cache') then begin .. end;
end;
问题是,如果程序用户想要在runetime中添加/拖放/插入组件、控件或对象,这是一种很弱的方法,需要额外的编码。通过这种方式,程序本身将自动在我的位置执行hald任务—知道调用什么以及何时调用:)
在(静态)窗体1上是(静态)PopupActionBar1。它有四个项目。第四项有子菜单-有三项。
包含子菜单项的第四项(PopupActionBar1.items[3])和三个子菜单项(PopupActionBar1.items[3]。items[0。。2] OnClick事件处理程序被设置为包含上面编写的If..Then语句的过程。
任务-通过升级发送方参数并使用其OOP功能-检查过程是否已从PopupActionBar1.Items[3]菜单项或其子菜单项(PopupActionBar1.Items[3]。Items[0]或PopupActionBar1.Items[3]。Items[1]或PopupActionBar1.Items[3]。Items[2])调用。
我试过各种语法。。。还尝试了使用TControl、TWinControl、TComponent进行类型转换操作。(TObject没有任何用处,因为它没有父对象(OLE除外)。。