3
檢查這個簡化的示例(真實場景是不同的),我想設置一個對象的嵌套屬性的值,在這種情況下設置顏色的使用RTTI將TLabel
組件的字體改爲clRed
。我如何設置使用RTTI的嵌套屬性的值
var
p : TRttiProperty;
p2: TRttiProperty;
c : TRttiContext;
begin
c := TRttiContext.Create;
try
p := c.GetType(Label1.ClassInfo).GetProperty('Font');
p2 := c.GetType(p.PropertyType.Handle).GetProperty('Color');
p2.SetValue(p.PropertyType.AsInstance,clred); //this line is not working
finally
c.Free;
end;
end;
還我試圖
p2.SetValue(Label1,clred);
非常感謝,羅伯特。 – Salvador 2011-05-15 19:21:57