Board index » delphi » Dynamic functions/Controls

Dynamic functions/Controls

Hi all!

I was wondering if any of you have any experience with created dynamic
functions/controls.  What I want to do is allow users to create their own
menu items via TMenuItem so when they specify a new menu item it opens other
application from my application. I have been using TMenuItem to
creating/adding new menu items but my questions comes up is how do I access
the OnClick events for these new menu items..I have renamed them and written
a click event with the newly named menu item but this is not working.

Any suggestions would be great!!

Thanks Brian

 

Re:Dynamic functions/Controls


Add to your form another procedure with identical declaration as the
OnClick event. Put there the code you want to perform when the event
ocurrs.

Then, when creating the new menu item add this method to its OnClick
property. ie:

 NewItem := TMenuItem.Create(..);
 NewItem.OnClick := MyClickEvent;

Quote
Brian wrote:

> Hi all!

> I was wondering if any of you have any experience with created dynamic
> functions/controls.  What I want to do is allow users to create their own
> menu items via TMenuItem so when they specify a new menu item it opens other
> application from my application. I have been using TMenuItem to
> creating/adding new menu items but my questions comes up is how do I access
> the OnClick events for these new menu items..I have renamed them and written
> a click event with the newly named menu item but this is not working.

> Any suggestions would be great!!

> Thanks Brian

--
juan antonio

\--------[ tres1...@email.com ]------------------[ ma108907 ]---\
/-------------------------------------[ ICQ #20980872 ]----------\
\---[ AOL IM tres1416 ]------------------------------------------/
 \-------------------------------------------------------[ ? ]---\

Re:Dynamic functions/Controls


Quote
Brian wrote:
> Hi all!

> I was wondering if any of you have any experience with created dynamic
> functions/controls.  What I want to do is allow users to create their own
> menu items via TMenuItem so when they specify a new menu item it opens other
> application from my application. I have been using TMenuItem to
> creating/adding new menu items but my questions comes up is how do I access
> the OnClick events for these new menu items..I have renamed them and written
> a click event with the newly named menu item but this is not working.

Create handler and assign it.

procedure TForm1.FormCreate(Sender: TObject);
begin
   MenuItem.OnClick := MyOnClick;
end;

procedure TForm1.MyOnClick(Sender: TObject);
begin
   // handler code in here
end;

end.

Re:Dynamic functions/Controls


Quote
In article <3a54fc69$1_2@dnews>, Brian wrote:
> I was wondering if any of you have any experience with created dynamic
> functions/controls.  What I want to do is allow users to create their own
> menu items via TMenuItem so when they specify a new menu item it opens other
> application from my application. I have been using TMenuItem to
> creating/adding new menu items but my questions comes up is how do I access
> the OnClick events for these new menu items..I have renamed them and written
> a click event with the newly named menu item but this is not working.

Brian,

create a new class (a simple TObject descendent will do) that will store all
the information provided by the user for a new menu item, e.g. the items
caption and the program the OnClick handler should execute. Add a method
to the object that conform to the TNotifyEvent prototype, so you can use it
as OnClick handler for the new menu item. The method executes the program
via ShellExecute. Add a TList instance (or TObjectList if you use D5) to your
program, e.g. as part of your main form.

For each new menu item the user wants to create you now first create an
instance of this new class and add it to the list. Then you create the new
menu item and assign it the objects method as OnClick handler. In fact you
can put the code to create the menu item into another method of the new class.
The class may want to keep a reference to the new menu item around, so it can
destroy the menu item when the object that serves it is destroyed, or at least
set the OnClick event to Nil.

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!
Note: Till Feb.2001 i will only visit the groups on weekends, so  be patient if i don't reply
immediately.

Other Threads