Sometimes we need to be aware of various state information while recording. For example, with a table cell that has the inputType property set to InputType_ComboBox, when you leave the cell, the text is copied from the combo box text to the table cell text. This does not occur automatically just by replaying all of the control events, so we need to set the text explicitly. The logical time to do that would be triggered by the queryRowColChg event method, as the old cell row, column, and text are still available. However, if the application suppresses queryRowColChg, we need to do it another way.
Another example is that it would be nice to rely on the TextBox class lostFocus event method to trigger the code generation to set the text box text, but if there is a Label class click method after entering the text, the lostFocus event method happens after the click method finishes. Since validation code is generated immediately following click events, the text has not yet been set and validation fails. There are numerous other examples.
The general technique for solving problems of this kind is to save off various state information; for example:
If a cellInputReady event method occurs on a Table class, an AtcgCellMate is saved, recording the correspondence between the cell and the associated control. If the associated control is a text box, when a lostFocus event method occurs on the text box, all cell mates are checked to see if there is a table cell into which the text needs to be set.
For each keyUp event method on a text box, the form, control, and text are saved. If a click event method occurs before the lostFocus event method on the text box, the code to set the text can be generated.
The fact that we are called back for each method individually means that we have to be careful about saving state. The receiver of the capture method (that is, global.atcgMyControl) is persistent, and we cannot begin or commit transactions without knowing the state of the tested application (for example, the commit would release most locks). This means we need to save everything off on app, or a transient referenced from app. At the moment, we keep these items on app, but if there get to be too many of them, we could invent a new helper class and use a single reference to it on app.
The AtcgCellMate class was originally implemented for controls associated with table cells (hence its name), but has since been expanded for general‑purpose state saving.