Search code examples
delphitext-formatting

Which are the TTextFormat(s) values (used in TextRect) and their meanings?


I want to apply some text formats in TextRect procedure but I don't found any documentation. In Delphi help, at TextRect reference, says that TextFormat variabile can have only 3 values: tfAutoText, tfText, tfPlainText. But here on StackOverflow I found some TextRect examples with other text format values, like tfEndEllipsis. I've searched this on Delphi help and I found other set with many text format values. When I tried them, the first set with those 3 values doesn't work at all, but the second set works. I'm confused. Which set is the good one ? It seems the second one is, because it's working. But then, what is the first set for ?

And what is the meaning of the following values (from the second set) ? :

  • tfCalcRect
  • tfEditControl
  • tfExpandTabs
  • tfExternalLeading
  • tfModifyString
  • tfNoClip
  • tfNoPrefix
  • tfRtlReading
  • tfWordBreak

The others are obvious...


Solution

  • The documentation is wrong. The three enumerated type values listed there (tfAutoText, tfText, tfPlainText) do not exist.

    You need to read the source of the Vcl.Graphics unit to get to the bottom of this. The source looks like this:

    type
      TTextFormats = (tfBottom, tfCalcRect, tfCenter, tfEditControl, tfEndEllipsis,
        tfPathEllipsis, tfExpandTabs, tfExternalLeading, tfLeft, tfModifyString,
        tfNoClip, tfNoPrefix, tfRight, tfRtlReading, tfSingleLine, tfTop,
        tfVerticalCenter, tfWordBreak, tfHidePrefix, tfNoFullWidthCharBreak,
        tfPrefixOnly, tfTabStop, tfWordEllipsis, tfComposited);
      TTextFormat = set of TTextFormats;
    

    And these values map directly onto the flags used by the Win32 API function DrawTextEx. You can find out what they mean by reading the documentation for that function.