setFocus();
The setFocus method of the Window class and Control class sets the focus to a window or control.
If the window is a form (that is, a form.setFocus method call), focus is restored to the last control that had the focus on that form, unless the form has never been activated, in which case the focus is given to the first enabled visible control in the tab order.
If the control cannot have the focus (for example, it is a Label, GroupBox, Frame, Picture, or Folder control) or if the control is disabled or is not visible, the focus is set to the next enabled visible control in the tab order. After the setFocus method is executed, any user input is directed to the control that gained the focus.
You can set focus to a visible form or control only. Setting the focus to a control on a sheet of a folder control that is not the current top sheet causes that sheet to become the current top sheet (that is, visible).
The methods in the following examples show the use of the setFocus method.
mnuDataPeriod_click(menuItem: MenuItem input) updating; vars form : Form; lpForm : ListPeriodsForm; begin form := app.getForm("ListPeriodsForm"); if form = null then create lpForm transient; lpForm.show; else lpForm := form.ListPeriodsForm; lpForm.setFocus; // set focus to this form lpForm.zOrder(1); lpForm.windowState := WindowState_Normal; endif; end; btnSearch_click(btn: Button input) updating; begin topObject := positionCollectionByKey(txtStartName.text, theCollectionIterator); refreshTable; txtStartName.setFocus; end;