Startediting Trigger

Putting a starting editing label in a text editor procedure should cause the code following the label to be run when editing begins. But it appears that the code is triggered if you click in a field to begin editing but it is not triggered if you tab into the field. Perhaps there is another setting that is necessary to make this happen. Any ideas on how to get the code to run when tabbing into the field?

There is definitely a problem with the code in the Procedure panel of a TextEditorObject not executing when entering the Text Editor via a tab. This is true whether it is using the startEditing method or set to execute with Start Editing option set in the Options pane. I have worked out a somewhat involved method to work around this issue. Probably not for the faint of heart but it does seem to be working reliably for me in my experimentations. So, with that warning, here we go…

First name each TextEditorObject with the name of the field they are displaying. As an example if you have a Text Editor that displays the “First” field you would name that Text Editor “First” (note that you can not use field names with a space for our purposes). Next create fileglobal variables - one named activeObject and one for each of the fields being displayed in the Text Editors named like “was” + the field name. Here are two fields used in my experimental database along with the activeObject variable:

letfileglobal activeObject=""
letfileglobal wasFirst=""
letfileglobal wasLast=""

Make a procedure (I called mine checkforchanges) that you will use to process any changes if the field values of the selected Text Editors are modified. This is code I used for experimentation with my two fields of First and Last:

If wasFirst<>First
    message "First field has changed"
    wasFirst=First
elseif wasLast<>Last
    message "Last field has changed"
    wasLast=Last
Endif
If info("timers") notcontains "ActiveObjectMonitor"
    starttimer "ActiveObjectMonitor","scope","window", "code",|||
    If info(“activeobject”)=""
        nop
    endif
    activeObject=info(“activeobject”)
    if wasActiveObject<>activeObject
        execute {was}+activeObject+{=}+activeObject
        wasActiveObject=activeObject
    endif
    |||
endif

Notice that there is a starttimer at the end of this code to restart the monitoring timer in case it stops for some reason. So, obviously you will have initially start this timer in a procedure after you have created the variables above. Just run the starttimer code above in the widow containing the Text Editors. In the procedure section of each Text Editor put call checkforchanges and set the Procedure Trigger options to End Editing and Tab. At this point you should be able to navigate your Text Editors either by tabbing through them or clicking and the checkforchanges procedure will not be triggered unless a related field’s value has changed.

The timer is monitoring the currently active Text Editor and setting a variable to the value of the field when first activating the related Text Editor. This value will be compared to the current value when the Text Editor is inactivated. If it is different that means there was a change and the relevant code will be run in the checkforchanges procedure. You can add as many Text Editors as you like with this method and just add more elseif statements to the code as needed.

There may be some problems or limitations I’m not aware of with what I have shown here but it should be a starting point if nothing else. Caveat emptor.