|Title: ||How to restore the focus to an edittext after the dialog has been made invisible?|
|Author: ||Roland Genske <email@example.com>|
When I hide a dialog using DLG SET ".visible",0 and later
make it visible again using DLG DO, the focus is set to the
first edittext in the dialog.
How can I automatically set the focus to the edittext
which had the focus before the dialog has been hidden?
This can be achieved using an user-defined attriute along with
two rules. If you work with modules, changes apply only to
the central module which contains the default definitions
and rules. Otherwise, these changes should be applied to any
of your .idm files:
object EqLastFocus := null;
on EDITTEXT select
this.window.EqLastFocus := this;
on WINDOW activate after
if (this.EqLastFocus <> null) then
if (this.focus <> this.EqLastFocus) then
this.EqLastFocus.focus := true;
In this approach, every window object contains an user-defined
attribute EqLastFocus which holds the last focused
edittext object if any. The last focused edittext object is
saved on entry ('select' rule above).
Whenever a window is activated (which implicitely happens if
it is made visible), EqLastFocus is checked if it has been
set to anything different from the currently focused object.
If this is the case, the focus is set to the object referred