Using "ThisElement" in programming
ThisElement is a special element reference that can be used in a Sesame programming statement to reference the Layout Element (LE) in which the code is currently running. It can be used anywhere an element reference is accepted, locally or in Global Code. ThisElement will return whichever element is running code.
// Return the length of whichever element is currently running code
vMyVar = @Len(ThisElement)
// Return the value of whichever element is currently running code
vMyVar = ThisElement
ThisElement is very valuable when writing generic code that you can copy-and-paste into any element without requiring changes. It also protects you from compile errors if you change the name of an element on your form.
For example, instead of this...LastName::OnElementEntry If @Len(LastName) > 50 { LastName = @Left(LastName, 50) }...you can do this...
FirstName::OnElementEntry If @Len(FirstName) > 50 { FirstName = @Left(FirstName, 50) }
LastName::OnElementEntry If @Len(ThisElement) > 50 { ThisElement = @Left(ThisElement, 50) }This makes it very easy to do similar things in multiple events. It also means that none of the above code will require any changes if you change the names of any of the elements.
FirstName::OnElementEntry If @Len(ThisElement) > 50 { ThisElement = @Left(ThisElement, 50) }
For more information on ThisElement, as well as similar commands such as SetThisElement, and UnsetThisElement, see the Sesame Programming Guide.
Note: ThisElement will not work properly in Form events because the currently running element is the Form itself.