Wie ist es mit so einer Lösung? Spricht irgend etwas dagegen?
Delphi-Quellcode:
class operator TMyRecord.Initialize(out Dest: TMyRecord);
var
LContext: TRttiContext; // Uses System.Rtti
LType: TRttiType;
LRecord: TRttiRecordType;
LField: TRttiField;
begin
LContext := TRttiContext.Create;
try
LType := LContext.GetType(TypeInfo(TMyRecord));
if LType.IsRecord then
begin
LRecord := LType.AsRecord;
//--
for LField in LRecord.GetFields do
begin
if (LField.FieldType.TypeKind=tkEnumeration) then
begin
if LField.FieldType.Handle = TypeInfo(Boolean) then
LField.SetValue(@Dest, false)
end else
if (LField.FieldType.TypeKind=tkUString) then
LField.SetValue(@Dest, '')
else
if (LField.FieldType.TypeKind=tkInteger) then
LField.SetValue(@Dest, 0)
else
if (LField.FieldType.TypeKind=tkFloat) then
LField.SetValue(@Dest, 0);
end;
end;
finally
LContext.Free;
end;
//Dest.Value := 10;
//Dest := Default(TMyRecord);
end;