|
The Amazing Thermos
A well dressed, cosmopolitan man entered
a large hardware store and while browsing around was approached by an eager sales
clerk. After remarking on all the wonderful items the store carried, the man inquired
of the clerk, "Of all the incredible items that you carry, which one is your
favorite?" The clerk, stunned for a moment, replied, "Well sir, I must
say it has to be the thermos. Yes, the thermos is amazing." The silence was
deafening. "What is amazing about a thermos?," inquired the man in disbelief.
The clerk smiled and explained, "It keeps my coffee hot and my iced tea cold."
The man stared at the clerk shaking his head. The clerk shrugged his shoulders and
questioned, "How do it know?"
Similarly, how will the button know
to inform the macro recorder when it gets clicked, and how will the macro recorder
know which button does what? Like the thermos, it must be designed to "know."
The macro recorder, once created, must first locate all the possible clients on its
parent form and notify each that it is open for service. Likewise, each button, once
informed of the macro recorder's services, must notify the macro recorder when it
gets clicked. Since the macro recorder cannot control when it gets created, it must
wait until all of its possible clients get created before taking inventory.
Upon creation, the macro recorder
will override the form's OnCreate event to create a list of buttons and checkboxes.
In creating the list of potential clients, the macro recorder will override each
client's OnClick event with a procedure that either records that a click occurred
for the client and calls the client's original OnClick handler, or simply calls the
client's original OnClick handler. In both cases, the original event handlers must
be left intact. This is the key to the amazing power of link associations.
|