Re: Trying again (MVP, please note): programmatically setting up event handlers



Albert D.Kallal wrote:
Who designs this stuff?

What environment have you used that allows runtime resolution of your
function names? I just curious as to what you used that allows your code to
resolve a name at runtime?

Hi, Albert! Let's see...how about PHP? :-)

I've worked for many years with the Java event handling mechanism,
which allows you to programmatically add as many event handlers as you
want for any event. You don't add a function, you add an object, but it
works out to the same thing--when the event occurs, some custom code
gets executed.

In any case, I wasn't asking for runtime resolution of function names,
I was asking for the ability to set up event handlers programmatically,
which is what most other languages allow (since they usually don't come
with a built-in IDE, they have to allow it).

addSomeCapability myButton, "custom text for button"...(and other
customization)

The idea is that this one subroutine would set up all the right event
handlers and all the right pieces of code.

Well, you can certainly write some code to open the form in design mode, and
make the changes. However, we are now talking about code that modifies other
code.

To define, and have your code change/modify at runtime is rather
daunting...do you think?

If that is what I wanted to do, then perhaps it would be..or maybe it
wouldn't. I'm happy to leave this to the philosophers. I just want to
be able to programmatically set up any and all event handlers.

As I mentioned, exactly what developer background do you come from where
this is common practices? Perhaps some scripting environment that is
evaluated at runtime, and not compile time?

Every language I know (other than VB for Access) that supports event
handlers, supports programmatically setting the event handlers. I'm
sure if Access didn't have a built-in IDE, it would, too. This has
nothing to do with scripting environments. I could event create a
system for doing this in VBA (after all, event handling is not usually
a language construct--it's part of the programming framework), but it
wouldn't help me out unless I could modify the base Form class to use
my event handler system.

It's even worse when I realize two days later that my button handling
code has a problem. I have to go back to all the little pieces of code
(event if each one is just one line) and make some changes. It's hard
to be sure that I caught all the changes.

I note sure why the one line of code that CALLS YOUR "general" error routine
would need to be modified? (or your general contorl code?).

In my case, the button handling code involves two event handlers on the
Form and one on the button.

Why would the number of parameters change there?

Since this is all theoretical examples (based on real problems I've run
into), let's assume I figure out a way to improve the usability of the
button, but it obsoletes a parameters I was passing it and requires a
different value. And perhaps the change even requires adding some code
to yet another event handler.

This makes no sense at all. If those controls call your "general" code, it
is VERY unlikely that the calling code will need to be changed, or modified.
At the very most, we would be talking about a VERY small instance when this
happens. Having to modify the main code module that those controls calls
certainly makes sense, and you will often have to modify that code. But,
modify the calling code of one line? Hum, not a problem here.

Let's agree to disagree.

You can download a free copy of mz-tools, and when in ANY routine, it will
pop up a list of CALLING routines. So, you could just open up your error
routine in the standard module, and a list of forms code that calls the code
would be available. However, this begs the question....are you really
saying that you have to change the parameters of those controls that calls
error code? I am hard pressed to ever much having to remember to do this,
and even more hard pressed to this ever being a developer problem.
.
Perhaps you are not explain something fully here?

I am, as always, thinking of much broader examples. Forget the error
handler--that's just an example of an event handler that's useless
without the parameters. I've been putting in some code that requires
multiple event handlers to function properly. So for each Form, I have
to go in and add multiple pieces of code in various places. Then if I
come up with a better idea, I may have to remove, revise and/or add to
all these little pieces of code.

In Java, not only would it be easy to centralize all this, but I could
even have the controls that are associated with this functionality
appear automatically!

VB for MS Access is the first language with event handling that I've
run into that requires the use of the IDE in order to get fully working
event handlers. Who designs this stuff? :-)

Anyway, the free mztools is a great vba add-in, and you can find it here:

http://www.mztools.com/

Thanks for the tip!

.