Du kannst mit PropInfo.PropertyType.TypeKind auch prüfen, um was für eine Eigenschaft es sich handelt.
Delphi-Quellcode:
procedure TodProp.ClearPointer(const od: Tod; p: Tod);
var
Context: TRttiContext;
RttiType: TRttiType;
PropInfo: TRttiProperty;
F: Boolean;
Attr: TCustomAttribute;
Value: TValue;
O: TObject;
PropValue: String;
begin
if (not Assigned(od)) or (not Assigned(p)) then
Exit;
od.HasNotOdPointer := True;
Context := TRttiContext.Create;
RttiType := Context.GetType(od.ClassType);
if Assigned(RttiType) then
begin
for PropInfo in RttiType.GetProperties do
begin
F := False;
for Attr in PropInfo.GetAttributes do
begin
if Attr is AttrOd then
F := True;
end;
if F then
begin
PropValue := '';
Value := TValue.Empty;
case PropInfo.PropertyType.TypeKind of // <<===============
tkClass:
begin
if PropInfo.IsWritable then
begin
od.HasNotOdPointer := False;
Value := PropInfo.GetValue(od);
if (not Value.IsEmpty) then
begin
O := Value.AsObject;
if O = p then
begin
Value := nil;
PropInfo.SetValue(od, Value);
end;
end;
end;
end;
//...
end;
end;
end;
end;
Context.Free;
end;