Skip to content

Instantly share code, notes, and snippets.

@martinusso
Last active February 24, 2020 03:19
Show Gist options
  • Save martinusso/3d435b5e1f3e6805676874bcd85dc66d to your computer and use it in GitHub Desktop.
Save martinusso/3d435b5e1f3e6805676874bcd85dc66d to your computer and use it in GitHub Desktop.
Clear objects with Run-Time Type Information (RTTI) In Delphi
procedure Clear;
var
t: TRttiType;
prop: TRttiProperty;
begin
t := TRttiContext.Create.GetType(Self.ClassType);
for prop in t.GetProperties do
begin
if not prop.IsWritable then Continue;
case prop.PropertyType.TypeKind of
tkInteger, tkInt64, tkFloat: prop.SetValue(Self, 0);
tkString, tkUString, tkWString: prop.SetValue(Self, '');
end;
end;
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment