How to attach one event handler to multiple objects

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
lelynx
Posts: 6
Joined: Sat May 17, 2008 3:06 pm

How to attach one event handler to multiple objects

Post by lelynx »

Hi all,

I hope you could help me.

I have a form on which I create several buttons by code.
The number of buttons will vary randomly.

I need these buttons to respond to a click event.
I would like to avoid having to create one event handler function for each button.

2 questions:

1- how can I attach an event handler to each of these buttons
2- how is it possible the event handler function be a single function?
3- how can I detect which button is responsible for the click event?

TIA,

Philippe
QuazzieEvil
Volunteer
Posts: 283
Joined: Tue Dec 04, 2007 6:38 pm
Location: Houston, TX

Re: How to attach one event handler to multiple objects

Post by QuazzieEvil »

you can assign a function/subroutine to any number of control events. simply goto the EVENT tab of the properties dialog, select an event, and proceed as usual.

in regards to detecting which button called the function, you can do so from the evnet parameter.

Code: Select all

Sub handler(Event As Object)
   Dim Button As Object

   REM for a button pressed event, the event.source refers to the button's view, to get the model, use access the Model property of the view
   Button=Event.Source.Model
    REM now you can get the button's name.   
   ButtonName=Button.Name
   ButtonLabel=Button.Label

End Sub
hope this helps
Post Reply