在DLL中做了两个菜单项,为什么只有第一个菜单项响应事件(200分)

  • 主题发起人 主题发起人 xia77
  • 开始时间 开始时间
X

xia77

Unregistered / Unconfirmed
GUEST, unregistred user!
我在DLL中做了两个菜单项,添加到主窗体中,只有第一个菜单项响应事件,第二个菜单项不响应事件,不知什么原因,代码如下,期盼熟悉的网友提供一些帮助。<br><br>一、DLL部分:<br><br>library ShowCaps;<br><br>uses<br> &nbsp;UnShowCaps in 'UnShowCaps.pas';<br><br>exports &nbsp; &nbsp; &nbsp;//输出过程<br> &nbsp;AddMenuItems;<br><br><br>begin<br>end.<br><br>------------<br><br>unit UnShowCaps;<br><br>interface<br><br>uses<br> &nbsp;Dialogs, Menus;<br><br>type<br> &nbsp;TMenuEvent = class<br> &nbsp;private<br> &nbsp; &nbsp;FItem1: TMenuItem;<br> &nbsp; &nbsp;FItem2: TMenuItem;<br> &nbsp;protected<br> &nbsp;public<br> &nbsp; &nbsp;constructor Create;<br> &nbsp; &nbsp;destructor Destory;<br><br> &nbsp; &nbsp;procedure StopClick(Sender: TObject);<br> &nbsp; &nbsp;procedure Time1Click(Sender: TObject);<br> &nbsp; &nbsp;<br> &nbsp; &nbsp;property Item1: TMenuItem read FItem1;<br> &nbsp; &nbsp;property Item2: TMenuItem read FItem2;<br> &nbsp;end;<br><br> &nbsp;procedure AddMenuItems(ParentMenu: TMainMenu); stdcall;<br><br>var<br> &nbsp;MenuClick: TMenuEvent;<br><br>implementation<br><br>procedure AddMenuItems(ParentMenu: TMainMenu);<br>begin<br> &nbsp;ParentMenu.Items[1].Add(MenuClick.Item1);<br> &nbsp;ParentMenu.Items[1].Add(MenuClick.Item2);<br>end;<br><br>constructor TMenuEvent.Create;<br>begin<br> &nbsp;inherited Create;<br><br> &nbsp;//创建新菜单项.<br> &nbsp;FItem1 := NewItem('停止', 0, false, true,<br> &nbsp; &nbsp;StopClick, 0, 'newStop');<br><br> &nbsp;FItem2 := NewItem('每句间隔', 0, false, true,<br> &nbsp; &nbsp;Time1Click, 0, 'newTime1');<br>end;<br><br>destructor TMenuEvent.Destory;<br>begin<br> &nbsp;FItem1.Free;<br> &nbsp;FItem2.Free;<br><br> &nbsp;inherited;<br>end;<br><br>//响应菜单项的事件<br>procedure TMenuEvent.StopClick(Sender: TObject);<br>begin<br> &nbsp;ShowMessage('停止事件');<br>end;<br><br>procedure TMenuEvent.Time1Click(Sender: TObject);<br>begin<br> &nbsp;ShowMessage('每句间隔事件');<br>end;<br><br>initialization<br> &nbsp;MenuClick := TMenuEvent.Create;<br> &nbsp;<br>finalization<br> &nbsp;MenuClick.Free;<br> &nbsp;<br><br>end.<br><br>------------<br><br>二、主窗体:<br><br>procedure AddMenuItems(ParentMenu: TMainMenu);<br> &nbsp;stdcall; external 'ShowCaps.dll';<br><br>var<br> &nbsp;Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br> &nbsp;AddMenuItems(MainMenu1);<br>end;<br><br>procedure TForm1.FormDestroy(Sender: TObject);<br>var<br> &nbsp;i: integer;<br>begin<br> &nbsp;for i := N2.Count - 1 Downto 0 do<br> &nbsp; &nbsp;N2.Remove(N2.Items);<br>end;
 
ParentMenu.Items[0].Add(MenuClick.Item1);<br> &nbsp;ParentMenu.Items[1].Add(MenuClick.Item2);试一下
 
abraveboy:你好!<br>您两句表示在第一个主菜单下添加第一个菜单项,在第二个主菜单下添加第二个菜单项。<br>我是在第二个主菜单下同时添加两个菜单项。<br>就按您的做法,也只能响应第一个事件。
 
二个对调一下测试。看毛病出在哪里
 
网中戏:你好!<br>对调,仍然响应一个事件。
 
后退
顶部