Last active
February 24, 2020 03:19
-
-
Save martinusso/3d435b5e1f3e6805676874bcd85dc66d to your computer and use it in GitHub Desktop.
Clear objects with Run-Time Type Information (RTTI) In Delphi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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