【发布时间】:2008-09-27 16:24:51
【问题描述】:
我正在编写一个 Delphi 专家。我需要能够将值写入作为对象的属性上的属性。例如。我在表单上有一个 GroupBox,我想编辑 Margins.Left 属性。我正在使用以下过程来执行此操作,但如果在标记线上给出了 AV。
该过程从(属性编辑器)中获取一个组件的属性名称(例如“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;
【问题讨论】: