我正在創建一個類似於對象檢查器的控件,所以我想將屬性的任何更改分配給相關對象。在Delphi中動態分配值
var
v:TValue ;
ctx : TRttiContext;
begin
// k.IsOrdinal := true ;
v := v.FromVariant(2) ;
ctx.GetType(tButton).GetProperty('Style').SetValue(Button1, v.AsOrdinal);
end;
上面是我的代碼,但我越來越無效類型轉換錯誤。
是否可以處理任何變量和枚舉(無需對象和記錄的,因爲它是很複雜)
謝謝,這就是我需要的 – VibeeshanRC 2012-02-03 12:43:04
我想你在這裏濫用泛型;嘗試只是'SetValue(Button1,TValue.From(TButton.TButtonStyle(2)));' – kludg 2012-02-03 13:13:54
@Serg你是正確的,你給的表單,它使用類型推斷,不會導致內部錯誤。但我並不濫用泛型。我使用的語法是完全有效的:http://docwiki.embarcadero.com/RADStudio/en/Declaring_Generics#Parameterized_Methods – 2012-02-03 13:26:02