|
Recording and Playback
When a user presses a button and generates
a click event for a client control, TMacroRecorder’s RecordEvent gets called instead
of what the application programmer designed. RecordEvent attempts to locate the client
control on TEventList. If it does not find the control, then the event is ignored.
Alternatively, an internal error could be raised. When it finds the control, if the
recorder is recording, then the control’s name is added to the macro, followed by
the macro separator. The separator assists in parsing out the control names later
during playback. Finally, if the programmer had defined an original event handler
for the control, it is next called.
During Playback, TMacroRecorder parses
out each client control name in turn, locates the control’s window handle and event
handler, posts the window messages, and calls the event handler. To users, the application
acts as if it were haunted by a ghost. The only detail missing is that the mouse
pointer does not track between clicks. Sticklers for detail can extend the Playback
method to add mouse pointer animation as desired.
The remainder of this article will
illustrate the macro recorder in use, so you will need to either download the code
from our download
area, or type it in as it appears. The downloadable
code includes a DCR (Delphi Component Resource) file that gives the TMacroRecorder
a custom glyph. This DCR is not required to install the TMacroRecorder. The DCR is
a 32 bit DCR and you will need to convert it to a 16 bit DCR to use it under Version
1.0 of Delphi. Although the code was developed for 32 bit Delphi, users of version
1.0 will find that it will operate under the 16 bit version with some simple changes.
To back-port the TMacroRecorder and
the example programs to version 1.0, first replace the "Windows" (WINDOWS.DCU)
32 bit reference in the "Uses" clause with "WinTypes" and "WinProcs"
in all PAS files. Next, comment out the line Application.Initialize in your project
source files. This is all that is required to run the examples in version 1.0 of
Delphi.
|