编写以下代码
procedure TForm1.Edit1ApplyStyleLookup(Sender: TObject);
var
Obj: TFmxObject;
begin
Obj := Edit1.FindStyleResource('background');
if Obj <> nil then
ShowMessage('Obj is not nil')
else
ShowMessage('Obj is nil');
end;
XE6中的代码运行良好,XE7内部Obj为零。 对不起,这是什么原因,怎么去Obj?
以下代码,对Obj的访问与NIL值相同:
TMyEdit = class(TEdit)
protected
procedure ApplyStyle;override;
...
procedure TMyEdit.ApplyStyle;
var
Obj: TFmxObject;
begin
inherited;
Obj := Self.FindStyleResource('background');
...
end;
答案 0 :(得分:0)
我遇到了与C ++ Builder XE7相同的问题。这就是我如何解决它。我创建了这个功能:
static Fmx::Types::TFmxObject* __fastcall FindStyle(
Fmx::Types::TFmxObject* AFmxObject, const System::UnicodeString AStyleLookup)
{
if(AFmxObject == NULL)
{
return NULL;
}
Fmx::Types::TFmxObject* Result = NULL;
const int LChildrenCount = AFmxObject->ChildrenCount;
for(int i = 0; i < LChildrenCount; ++i)
{
if(AFmxObject->Children->Items[i]->StyleName == AStyleLookup)
{
Result = AFmxObject->Children->Items[i];
break;
}
Result = FindStyle(AFmxObject->Children->Items[i], AStyleLookup);
if(Result != NULL)
{
break;
}
}
return Result;
}
只需调用这样的函数:
#if __CODEGEARC__ < 0x0690
Fmx::Types::TFmxObject* LStyleResource = LEdit->FindStyleResource("background");
#else
Fmx::Types::TFmxObject* LStyleResource = FindStyle(LEdit, "background");
#endif
这并不复杂,所以我想用Delphi编写它会很容易。