How to call AcceptText
When a user modifies a DataWindow item then immediately changes focus to another control in the window, the DataWindow control does not accept the modified data—the data remains in the edit control. Use the AcceptText method in this situation to ensure that the DataWindow object contains the data the user edited.
However, you must not call AcceptText in the LoseFocus event or in a user event posted from LoseFocus if the DataWindow control still has focus. If you do, an infinite loop can occur.
The problem Normally, new data is validated and accepted when the user moves to a new cell in the DataWindow. If the new data causes an error, a message box displays, which causes the DataWindow to lose focus. If you have also coded the LoseFocus event or an event posted from LoseFocus to call AcceptText to validate data when the control loses focus, this AcceptText runs because of the message box and triggers an infinite loop of validation errors.
The solution It is desirable to validate the last changed data when the control loses focus. You can accomplish this by making sure AcceptText gets called only when the DataWindow control really has lost focus. The third PowerBuilder example illustrates how to use an instance variable to keep track of whether the DataWindow control has focus. The posted event calls AcceptText only when the DataWindow control does not have focus.
This is a change from previous versions of PowerBuilder. Previously, the posted user event would run while the message box for the validation error was displayed. Now, it runs after the message box is dismissed, causing another validation error to occur and another message box to be displayed, resulting in an infinite loop.