Board index » delphi » Adding an OnClick Event from a DLL

Adding an OnClick Event from a DLL

I have a DLL that I call from the Main.exe with the following
call:

{.EXE code}
RegisterDLL(MyForm, MyMenuItem);

in the .DLL I add some menu items successfully to it:
{DLL Code}

procedure RegisterDLL(wnd: TForm; MyMenuItem: TMenuItem);
begin
  MyObject := TMyObject.Create(wnd);
  MyObject.RegMenu(wnd, MyMenuItem);
end;

procedure TMyObject.RegMenu(wnd: TForm; MyMenuItem: TMenuItem);
var
  mnu: TMenuItem;
begin
  mnu.Create(wnd);
  mnu.Caption := '&My New Item';
  mnu.Name := 'mnuMyNewMenuItem';
  mnu.OnClick := MenuClick;
  mnu.Enabled := True;
  mnu.Visible := True;
  MyMenuItem.Add(mnu);
end;

procedure TMyObject.MenuClick(Sender: TObject);
begin
  {<<<<< HERE I GET A GPF >>>>>>>}
  TMenuItem(StrList.Objects[0]).Caption := 'I got You Babe';
end;

The housekeeping for creating the menu item and cleaning it up
works fine, but when I click on the menu Item, I get a GPF.

Can anyone please help?

--
Brahm van Niekerk
CEO - Elgin Data Development Corporation (PTY) Ltd.
P.O. Box 140, Elgin, South Africa
Tel. 027 83 270 2850, Fax 027 21 859 5028
mailto:br...@iafrica.com

 

Re:Adding an OnClick Event from a DLL


I pass the main form to a procedure in a DLL.  From the DLL, I
then add several menu items (with event handlers) from a DLL.  

It shows correctly on the main menu, but when I select any of
these new menu items in the EXE, it fires other events from
within the .EXE instead of the events in the DLL.

Can somebody help!
--
Brahm van Niekerk
CEO - Elgin Data Development Corporation (PTY) Ltd.
P.O. Box 140, Elgin, South Africa
Tel. 027 83 270 2850, Fax 027 21 859 5028
mailto:br...@iafrica.com

Re:Adding an OnClick Event from a DLL


Quote
> I pass the main form to a procedure in a DLL.  From the DLL, I
> then add several menu items (with event handlers) from a DLL.  

I'm assuming that you properly assign the Newitem.onclick property
to the event handler.

Quote
> It shows correctly on the main menu, but when I select any of
> these new menu items in the EXE, it fires other events from
> within the .EXE instead of the events in the DLL.

Precisely which events does it call?  On the same thread, why the
heck would you ever want to do this!?!?  8-)

--
--------------------------
Eric Lawrence
Delta Programming Group
Delta...@juno.com

Re:Adding an OnClick Event from a DLL


Quote
Eric Matthew Lawrence wrote:

> > I pass the main form to a procedure in a DLL.  From the DLL, I
> > then add several menu items (with event handlers) from a DLL.

> I'm assuming that you properly assign the Newitem.onclick property
> to the event handler.

All the NewItem.OnClick events are assigned properly.  (I AM
SURE!)

Quote
> > It shows correctly on the main menu, but when I select any of
> > these new menu items in the EXE, it fires other events from
> > within the .EXE instead of the events in the DLL.

> Precisely which events does it call?  On the same thread, why the
> heck would you ever want to do this!?!?  8-)
> It simply assigns events from the main menu from within the .EXE.  

For the first MenuItem I add, it fires the event from the first
menu item in the main menu in the .EXE.   Thereafter the second
MenuItem fires the second menu item in the main menu in the .EXE
and so on ...

--
Brahm van Niekerk
CEO - Elgin Data Development Corporation (PTY) Ltd.
P.O. Box 140, Elgin, South Africa
Tel. 027 83 270 2850, Fax 027 21 859 5028
mailto:br...@iafrica.com

Re:Adding an OnClick Event from a DLL


Quote
Eric Matthew Lawrence wrote:

> > I pass the main form to a procedure in a DLL.  From the DLL, I
> > then add several menu items (with event handlers) from a DLL.

> I'm assuming that you properly assign the Newitem.onclick property
> to the event handler.

All the NewItem.OnClick events are assigned properly.  (I AM
SURE!)

Quote
> > It shows correctly on the main menu, but when I select any of
> > these new menu items in the EXE, it fires other events from
> > within the .EXE instead of the events in the DLL.

>Precisely which events does it call?  On the same thread,

It simply assigns events from the main menu from within the .EXE.  
For the first MenuItem I add, it fires the event from the first
menu item in the main menu in the .EXE.   Thereafter the second
MenuItem fires the second menu item in the main menu in the .EXE
and so on ...

Quote
>why the
> heck would you ever want to do this!?!?  8-)
> We will eventually work as a team on a massive project that will

involve several .DLLs attached to a single .EXE.  It would mean
that a single call to the .DLL will enable each .DLL programmer
to add his/her own menu items with their own events.

--
Brahm van Niekerk
CEO - Elgin Data Development Corporation (PTY) Ltd.
P.O. Box 140, Elgin, South Africa
Tel. 027 83 270 2850, Fax 027 21 859 5028
mailto:br...@iafrica.com

Other Threads