我正在写Delphi专家。我需要能够写一个属性值属性是一个对象。例如。我在窗体上有一个GroupBox,我想编辑Margins.Left属性。我正在使用以下过程来做到这一点,但是如果在标记线上给出AV。Delphi OTA和RTTI bug
该过程从(属性编辑器)属性名称(例如'Margins.Left')和新值中抽取一个组件,解析出属性名称,获取对象,读取当前值并尝试更改它如果不同。然后它调用一个方法记录任何更改。
procedure EditIntegerSubProperty(Component: IOTAComponent;const PropName: String;NewValue: Integer);
var AnObject: TObject;
TK: TTypeKind;
At: Integer;
AClassName, APropName: String;
PropInfo: PPropInfo;
OldValue: Integer;
begin
At := Pos('.', PropName);
if At < 1 then
raise Exception.Create('Invalid SubProperty Name: '+PropName);
AClassName := Copy(PropName, 1, At-1);
APropName := Copy(PropName, At+1, length(PropName));
TK := Component.GetPropTypeByName(AClassName);
if TK <> tkClass then
EXIT;
AnObject := GetObjectProp((Component as INTAComponent).GetComponent, AClassName);
if PropIsType(AnObject, APropName, tkInteger) then
begin
OldValue := GetInt64Prop(AnObject, APropName);
if OldValue <> NewValue then
begin
SetInt64Prop(AnObject, APropName, NewValue); <----AV HERE
ChangeLogInteger(Name, PropName, OldValue, NewValue);
end;
end;
end;
谢谢。工作很好。 – 2008-09-27 19:35:20