Setting Text Parameters in FireMonkey - RAD Studio
Setting Text Parameters in FireMonkey - RAD Studio
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)