FMX.TextLayout.TTextAttribute

Aus RAD Studio API Documentation
Wechseln zu: Navigation, Suche

Delphi

  TTextAttribute = record
  public
    Font: TFont;
    Color: TAlphaColor;
    constructor Create(const AFont: TFont;
                       AColor : TAlphaColor); overload;
    constructor Create(const AExisting: TTextAttribute;
                       const ANewFont: TFont); overload;
    constructor Create(const AExisting: TTextAttribute;
                       ANewColor: TAlphaColor); overload;
  end;

C++

struct DECLSPEC_DRECORD TTextAttribute
{
public:
    Fmx::Graphics::TFont* Font;
    System::Uitypes::TAlphaColor Color;
    __fastcall TTextAttribute(Fmx::Graphics::TFont* const AFont, System::Uitypes::TAlphaColor AColor)/* overload */;
    __fastcall TTextAttribute(const TTextAttribute &AExisting, Fmx::Graphics::TFont* const ANewFont)/* overload */;
    __fastcall TTextAttribute(const TTextAttribute &AExisting, System::Uitypes::TAlphaColor ANewColor)/* overload */;
    TTextAttribute() {}
};

Eigenschaften

Typ Sichtbarkeit Quelle Unit Übergeordnet
record
struct
public
FMX.TextLayout.pas
FMX.TextLayout.hpp
FMX.TextLayout FMX.TextLayout


Beschreibung

Enthält Textattribute.

Font enthält die Schriftart des Textes. Color enthält die Farbe des Textes.

TTextAttribute kann auf drei Arten erstellt werden:

  • Aus einer vorhandenen Schriftart und Farbe
  • Aus einem vorhandenen TTextAttribute mit einer neuen Farbe
  • Aus einem vorhandenen TTextAttribute mit einer neuen Schriftart


Hinweis: Ab RAD Studio 10.2 Tokyo Release 3 gibt die Klasse TTextLayout keine TFont-Instanz im ersten Konstruktor frei, sondern das Programm muss die TFont-Instanz entfernen.
Auf anderen als ARC-Plattformen, einschließlich Windows und macOS, müssen Sie die Methode Free manuell aufrufen, wenn eine TFont-Instanz, die den ersten Parameter von TTextAttribute.Create verwendet, nicht mehr gebraucht wird.
Bei ARC-Plattformen entfernt ARC die Instanz, wenn sie nicht verwendet wird.

Siehe das folgende Beispiel:

Layout := TTextLayoutManager.TextLayoutByCanvas(self.Canvas.ClassType).Create;
try
 BoldFont := TFont.Create;
 try
   ATTR1 := TTextAttribute.Create(BoldFont,TAlphaColorRec.Blue); 
   ATTR2 := TTextAttribute.Create(ATTR1,TAlphaColorRec.Red);


   Layout.AddAttribute(TTextRange.Create(0,5), ATTR1);
   Layout.AddAttribute(TTextRange.Create(12,5), ATTR2);


 finally
   BoldFont.Free;  // for ARC platform, Free method does nothing. This code keeps single source for all platforms.
 end;
finally
 FreeAndNIL(Layout);
end;

Siehe auch