Einzelnen Beitrag anzeigen

hzzm

Registriert seit: 8. Apr 2016
103 Beiträge
 
Delphi 10 Seattle Professional
 
#1

RTTI: GetPropValue(TTimeSpan)

  Alt 27. Jun 2019, 10:58
Delphi-Version: 10 Seattle
Guten Tag,

ich habe gerade das Problem, dass ich in TypInfo/RTTI den Wert von einer TTimeSpan so holen muesste
Delphi-Quellcode:
function RetrieveValue(AConcreteItem: TPersistent; APropIndex: Integer): Variant;
var
  LPropCount: Integer;
  LPropList: PPropList;
  LType: TClass;
begin
  LType := AConcreteItem.ClassType;
  LPropCount := GetTypeData(LType.ClassInfo)^.PropCount;
  GetMem(LPropList, LPropCount * SizeOf(Pointer));
  GetPropInfos(LType.ClassInfo, LPropList);
  if LPropList[APropIndex].PropType^.Name = 'TTimeSpanthen
    Result := GetStrProp(AConcreteItem, LPropList[APropIndex]) // <<-- Result = ''
  else
    Result := GetPropValue(AConcreteItem, LPropList[APropIndex], False);
end;
So geht das natuerlich nicht. TTimeSpan ist ein Record, darauf ist GetPropValue nicht vorbereitet.
Ich muesste eigentlich eine Ebene tiefer in GetPropValue einen cast String(TTimeSpan) durchfuehren, dann waere alles OK.

Wie kann ich das elegant beheben?
  Mit Zitat antworten Zitat