GetObjectProp(Fonte, 'Style')
不会工作,因为Style
首先不是一个基于对象的属性,它是一个Set
基于属性。和GetPropValue(Estilo, 'fsBold', true)
完全是错误的(并不是说你无论如何都可以调用它),因为fsBold
不是财产,它是成员TFontStyle
枚举。要检索Style
属性值,你必须使用GetOrdProp(Fonte, 'Style')
, GetSetProp(Fonte, 'Style')
, or GetPropValue(Fonte, 'Style')
相反(作为integer
, string
, or variant
, 分别)。
话虽如此,一旦您检索到TextSettings
对象,您根本不需要使用 RTTI 来访问它Font.Style
属性,直接访问属性即可。
试试这个:
procedure Tfrm1.aoClicarComponente(Sender: TObject);
var
Componente_cc: TControl;
TextSettings: TTextSettings;
begin
Componente_cc := ...;
if IsPublishedProp(Componente_cc, 'TextSettings') then
begin
TextSettings := GetObjectProp(Componente_cc, 'TextSettings') as TTextSettings;
Edit1.Text := BoolToStr(TFontStyle.fsBold in TextSettings.Font.Style, true);
end;
end;
更好(也是首选)的解决方案是根本不使用 RTTI。 FMX 类具有TextSettings
物业还实施ITextSettings http://docwiki.embarcadero.com/Libraries/en/FMX.Graphics.ITextSettings正是针对这种情况的接口,例如:
procedure Tfrm1.aoClicarComponente(Sender: TObject);
var
Componente_cc: TControl;
Settings: ITextSettings;
begin
Componente_cc := ...;
if Supports(Componente_cc, ITextSettings, Settings) then
begin
Edit1.Text := BoolToStr(TFontStyle.fsBold in Settings.TextSettings.Font.Style, true);
end;
end;
阅读 Embarcadero 的文档了解更多详细信息:
在 FireMonkey 中设置文本参数 http://docwiki.embarcadero.com/RADStudio/en/Setting_Text_Parameters_in_FireMonkey