0% found this document useful (0 votes)
189 views

Setting Text Parameters in FireMonkey - RAD Studio

The document discusses setting text parameters in FireMonkey using the TTextSettings class and ITextSettings interface. It provides an overview of how TTextSettings defines properties for controlling text appearance and how ITextSettings allows modifying these properties independently of the text object's type. The document also notes that the StyledSettings property determines whether text property changes are applied or overridden by style settings.

Uploaded by

Phaty Chirana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
189 views

Setting Text Parameters in FireMonkey - RAD Studio

The document discusses setting text parameters in FireMonkey using the TTextSettings class and ITextSettings interface. It provides an overview of how TTextSettings defines properties for controlling text appearance and how ITextSettings allows modifying these properties independently of the text object's type. The document also notes that the StyledSettings property determines whether text property changes are applied or overridden by style settings.

Uploaded by

Phaty Chirana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Show: Delphi C++

DisplayPreferences

SettingTextParametersinFireMonkey
FromRADStudio

Contents
1VisualTextParameters
2UsingtheITextSettingsInterface
3UsingtheStyledSettingsProperty
4SeeAlso
GoUptoFireMonkeyApplicationDesign
IntheTTextSettingsclassandtheITextSettingsinterface,FireMonkeyprovidesauniversaltoolformanaging
appearanceparametersoftextobjects.

VisualTextParameters
TheTTextSettingsclassdeclarestheTFont.Family,TFont.Size,TFont.Style,FontColor,HorzAlign,VertAlign,
Trimming,WordWrap,andFontColorForStatepropertiesdefiningvisualparametersofatextrepresentationand
methodsmanagingthesepropertiesincomponentsrenderingtextobjects.TheTTextSettingsclassdefines
featuresprovidingthepossibilitytospecifyhowoutputtextsaredrawnincomponents.Forexample,youcan
write:
Delphi:
Label1.TextSettings.FontColor:=MyColor;

C++:
Label1>TextSettings>FontColor=MyColor;

ThiscodesetsthepublishedpropertyTLabel.FontColoroftheTLabeltypeobject,whichactuallyinheritsthe
TTextSettings.FontColorproperty.However,touseTTextSettingsproperties,firstoneneedstoknowthetype
ofthecomponent(TLabelinthisexample).

UsingtheITextSettingsInterface
TheITextSettingsinterfacedeclaresmethodsandpropertiestomanagevisualparametersofatext
representationintheTTextSettingstypetextobjectsindependentlyofparticulartypescontainingthe
components.
ClassesusingtheTTextSettingstypetextobjectsTMemo,TCustomEdit,TTextControl,andtheirdescendants
havethepublicpropertyTextSettingsoftheTTextSettingstypeandtheyimplementtheITextSettings
interface.UsingthemethodsandthepropertiesdeclaredinITextSettings,youcanmanagetextrepresentation
propertiesdeclaredinTTextSettingsinthecomponenttypeindependentstyle.

Forexample,youmightnotknowtheparticulartypeofatextobjectinacomponent.Forexample,atextobject
canbeoftheTTextorTTextControltype.TheseclasseshavetheColorandFontColorcolorproperties
respectively.Generally,tosetthecolortooneoftheseproperties,oneneedstofirstlycheckthetypeofan
objectinstanceandthencastthecolortypeasfollows:
ifObjisTTextthen
TText(Obj).Color:=MyColor
elseifObjisTTextControlthen
TTextControl(Obj).FontColor:=MyColor;

TheusageoftheITextSettingsinterfacemakesthistaskmuchmoresimpleanduniversal:
Delphi:
procedureTForm12.Button1Click(Sender:TObject);
var
Settings:ITextSettings;
Instance:TComponent;
I:Integer;
begin
Instance:=Button1;
forI:=0toChildrenCount1do
begin
Instance:=Children[I];
ifIInterface(Instance).QueryInterface(ITextSettings,Settings)=S_OKthen
begin
//usingITextSettingsmethodsandproperties:
//TextSettings:TTextSettings,
//DefaultTextSettings,
//StyledSettings
//tochangepropertiesoftextobjects
Settings.TextSettings.BeginUpdate;
try
Settings.TextSettings.Font.Size:=18;
ifTStyledSetting.SizeinSettings.StyledSettingsthen
Settings.StyledSettings:=Settings.StyledSettings[TStyledSetting.Size]
//showFont.Size:=18
else
Settings.StyledSettings:=Settings.StyledSettings+[TStyledSetting.Size];
//restoreshowingFont.Sizeloadedfromastyle
finally
Settings.TextSettings.EndUpdate;
end;
end;
end;
end;

C++:
void__fastcallTForm1::Button1Click(TObject*Sender){

_di_ITextSettingsSettings;

TComponent*Instance=newTComponent(Form1);

intI;

Instance=Button1;

for(I=0;I<ChildrenCount;I++){

Instance=Children>Items[I];

if(Instance>GetInterface(Settings)){

Settings>TextSettings>BeginUpdate();

try{

Settings>TextSettings>Font>Size=18;

if(Settings>StyledSettings.Contains(TStyledSetting::Size)){

Settings>StyledSettings=

Settings>StyledSettings>>TStyledSetting::Size;

else{

Settings>StyledSettings=

Settings>StyledSettings<<TStyledSetting::Size;

catch(Exception*e){

Settings>TextSettings>EndUpdate();

Settings>TextSettings>EndUpdate();

YoucanjustretrievetheITextSettingsinterfacetypeobjectintheSettingsvariable.Incaseofsuccess,the
returnvalueofSettingsshouldn'tbenil.Inthiscase,theparticulartypeofInstanceisnotimportant.Whatis
importantisthattheobtainedIInterface(Instance)interfaceobjectcontainsthefollowingproperties:
TextSettings,DefaultTextSettings,StyledSettings.Usingtheseproperties,youcanchangetextpropertiesofany
typesoftheTTextSettingstypetextobjects.

UsingtheStyledSettingsProperty
WhenchangingtextrepresentationpropertiesoftheTTextSettingstypeobjects,rememberthatwhenyouare
changingthevalueofaproperty(oftheTextSettings.Font.Sizepropertyinthepreviousexample),thenthe
actualchangingoftheobject'sviewhappensonlyiftheITextSettings.StyledSettingspropertydoesnotcontain
theTStyledSetting.Sizeconstant.The"RelationbetweenTStyledSettingconstantsandTTextSettings
properties"tableshowswhichTStyledSettingconstantscontrolhandlingoftheTTextSettingstext
representationproperties.

SeeAlso
FMX.Graphics.TTextSettings
FMX.Graphics.ITextSettings
System.Classes.TComponent.QueryInterface
Retrievedfrom"http://docwiki.embarcadero.com/RADStudio/Seattle/e/index.php?
title=Setting_Text_Parameters_in_FireMonkey&oldid=236339"
Categories: FMX XE3
Thispagewaslastmodifiedon5January2015,at07:26.
HelpFeedback(QP,email)

You might also like