ActiveControl
ActiveControl
Control active at last event
Runtime-only OBJECT reference property
Applies to: Form
Introduced in KCML version 5.03
This object property refers to the control that was active (i.e. had focus) at the time the current event was triggered. You can use it within an event handler and in particular it is very useful within a menu Select() event especially when that selection is linked to a toolbar button. Toolbar buttons and menu selections do not switch focus away from the control that was active when the button was clicked.
Consider the case of a paste feature that updates a controls text$ property. The form might contain lots of grid cells and edit controls. By clicking the toolbar button some text can be pasted into the control. This can be done with a single event handler for the button as in the example which simulates the Cut and Paste features of the Windows clipboard by using a local variable.
- DEFFORM Form1()={.form,.form$,.Style=0x50c000c4,.Width=216,.Height=94,.text$="Cut and paste without using clipboard",.Id=1024,.Menu=.mnuControl1}, \ {.editControl1,.kcmldbedit$,.Style=0x50810080,.Left=13,.Top=12,.Width=49,.Height=14,.Id=1000}, \ {.editControl4,.kcmldbedit$,.Style=0x50810080,.Left=90,.Top=12,.Width=49,.Height=14,.Id=1003}, \ {.editControl2,.kcmldbedit$,.Style=0x50810080,.Left=13,.Top=39,.Width=49,.Height=14,.Id=1001}, \ {.editControl3,.kcmldbedit$,.Style=0x50810080,.Left=13,.Top=66,.Width=49,.Height=14,.Id=1002}, \ {.ok,.button$,.Style=0x50010001,.Left=160,.Top=6,.Width=50,.Height=14,.text$="OK",.__Anchor=5,.Id=1}, \ {.cancel,.button$,.Style=0x50010000,.Left=160,.Top=23,.Width=50,.Height=14,.text$="Cancel",.__Anchor=5,.Id=2}, \ {.mnuControl1,.Menu$,.Id=1004,.file={.text$="File"},.edit={.Flag=144,.text$="Edit"},.editcut={.text$="Cut",.Picture=.Cut,.Select()},.editpaste={.Flag=128,.text$="Paste",.Picture=.Paste,.Select()}} LOCAL DIM MyClipboard$100 - DEFEVENT Form1.mnuControl1.editcut.Select() LOCAL DIM OBJECT a OBJECT a = .form.ActiveControl IF (a.Id > 10) REM don't clobber buttons MyClipboard$ = a.text$ a.text$ = "" END IF END EVENT - DEFEVENT Form1.mnuControl1.editpaste.Select() LOCAL DIM OBJECT a OBJECT a = .form.ActiveControl IF (a.Id > 10) REM don't clobber buttons a.text$ = MyClipboard$ END IF END EVENT FORM END Form1 Form1.Open()