我将值存储在 xml 和 lua 代码中,并通过 RTTI 访问对象的属性。
var
o, v: TValue; // o is current object
a: TStringDynArray; // params as array
ctx: TRttiContext;
tt: TRttiType;
p: TRttiProperty;
pt: PTypeInfo;
begin
...
ctx := TRttiContext.Create;
try
o := GetLastClassInParams(ctx, obj, a, param_idx);
tt := ctx.GetType(o.TypeInfo);
if high(a) < param_idx then
raise Exception.Create(S_FN + S_NOP);
p := tt.GetProperty(a[param_idx]);
if p = nil then
raise Exception.Create(S_FN + S_PNE + a[param_idx]);
pt := p.PropertyType.Handle;
case p.PropertyType.TypeKind of
tkInteger: v := TValue.From<integer>(integer(Value));
tkEnumeration: v := TValue.FromOrdinal(pt, GetEnumValue(pt, VarToStr(Value)));
tkUString: v := TValue.From<string>(VarToStr(Value));
tkFloat: v := TValue.From<double>(double(Value));
tkSet: begin
temp_int := StringToSet(pt, VarToStr(Value));
TValue.Make(@temp_int, pt, v);
end;
else v := TValue.FromVariant(Value);
end;
p.SetValue(o.AsObject, v);
我可以使用许多属性Width,例如Lines.TextTMemo 等,甚至使用Panels[0].WidthTStatusBar (其中 Panels 是 TCollection 的后代),但类似TStringGrid.Cells[x, y]的事情是我无法解决的。有关于 Embarcadero 的帮助和一些功能,比如GetIndexedProperty(也许这就是我需要的),但那里的解释和"Gets Indexed Property".
TStringGrid.Cells[x,y]如果我将值存储为字符串,如何在运行时设置和获取RTTI "Cells[1,1]"?