Search code examples
delphilabelstatic-text

What are there advantages to using Static Text instead of Label in Delphi?


From the docwiki for labels:

You place a label on a form when you need to identify or annotate another component such as an edit box or when you want to include text on a form. The standard label component, TLabel, is a non-windowed control, so it cannot receive focus; when you need a label with a window handle, use TStaticText instead.

What does the statement "when you need a label with a window handle, use TStaticText instead" mean?


Solution

  • At work, we use a TStaticText when we want our UI automation testing tool to 'read' the text of a "label". Most of the interaction is done by Windows API messaging, so a TStaticText will respond to GetWindowText, while a TLabel will not. This is a simplistic overview on how we use TStaticText and a TLabel.