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