-
-
Save njmube/f1962dcee3b38829a5fdd534d4fefcc9 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