To ease in coding and allow it to be more generic for multiple controls, this can be used to reference the control that is running the code. This allows the code or control to be copy/pasted or the control's name changed while allowing code to still operate.
For example, in a control called txtTest, we wish to have code to change the backColor to red if the entered value is greater than 100, or to green if not. !if [txtTest] > 100 !then !txtTest.backColor=RED !else !txtText.backColor=GREEN
This can be written as: !if [[this]] > 100 !then !this.backColor=RED !else !this.backColor=GREEN
If the control's name is changed, this code will still function properly. It can also lead to fewer coding mistakes.
Note that when referencing the control, [this] will return the control name that is running the code. [[this]] will resolve the name to its default value. [this.property] can be used to return as specific property or value. !this will also resolve to the control's name, such as: !this = 20
Toggle Button References with Update Values
When a control, such as toggle button, is using Update Value to set its state to some property, such as whether logging is enable or not, use of [[this]] is not recommended due to the asynchronous operation of updates and code processing.
Say for example, a toggle button is being updated to show the status of logging with a logging control: [log4Meters.loggingEnabled]
By clicking the button to change the state with will sometimes NOT update properly as the state of the button may be updated based on logging being enabled before the code is processed, causing [[this]] to be the incorrect value desired : !log4Meters.loggingEnabled=[[this]]
It is best to ensure the proper setting of the property is performed using its Event Triggers: <on>!log4Meters.loggingEnabled=1 <off>!log4Meters.loggingEnabled=0
|