Lantica Software Support Center
Lantica Software Home Page
Order Sesame Getting Started Support Center Contact Us Company Downloads Q&A ™  
Search

Knowledgebase Home

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)
} 

FirstName::OnElementEntry If @Len(FirstName) > 50 { FirstName = @Left(FirstName, 50) }
...you can do this...
LastName::OnElementEntry
If @Len(ThisElement) > 50
{
	ThisElement = @Left(ThisElement, 50)
}

FirstName::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.

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.
Properties ID: 000223   Views: 1246   Updated: 13 years ago
Filed under:
Programming
Form/Database Design
Working With Your Data / Records

Copyright Lantica Software, 2003-2025 All rights reserved