From 5d9e93df7a7ce59640ae1ccd9cbaaf8414ff146f Mon Sep 17 00:00:00 2001 From: "kikobatery@hotmail.com" Date: Tue, 9 Jan 2024 22:45:57 -0300 Subject: [PATCH] Fix Update Fields Enum --- SimpleRTTI.pas | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/SimpleRTTI.pas b/SimpleRTTI.pas index 215ed38..43dab6f 100644 --- a/SimpleRTTI.pas +++ b/SimpleRTTI.pas @@ -670,6 +670,21 @@ function TSimpleRTTI.FieldsInsert(var aFields: String): iSimpleRTTI; if prpRtti.IsIgnore then Continue; + if (prpRtti.IsEnum) then + begin + case prpRtti.PropertyType.TypeKind of + tkInteger, tkInt64, tkFloat: + if prpRtti.GetValue(Pointer(FInstance)).AsInteger = 0 then + Continue; + tkWChar, + tkLString, + tkWString, + tkUString, + tkString: + if prpRtti.GetValue(Pointer(FInstance)).AsString = EmptyStr then + Continue; + end; + end; aFields := aFields + prpRtti.FieldName + ', '; end; finally @@ -713,10 +728,14 @@ function TSimpleRTTI.Param (var aParam : String) : iSimpleRTTI; typRtti : TRttiType; prpRtti : TRttiProperty; Info : PTypeInfo; + DictionaryFields: TDictionary; + FieldValue: Variant; begin Result := Self; Info := System.TypeInfo(T); ctxRtti := TRttiContext.Create; + DictionaryFields := TDictionary.Create; + Self.DictionaryFields(DictionaryFields); try typRtti := ctxRtti.GetType(Info); for prpRtti in typRtti.GetProperties do @@ -729,6 +748,10 @@ function TSimpleRTTI.Param (var aParam : String) : iSimpleRTTI; if prpRtti.IsEnum then begin + DictionaryFields.TryGetValue(prpRtti.FieldName, FieldValue); + if FieldValue = EmptyStr then + Continue; + aParam := aParam + ':' + prpRtti.FieldName + '::' + prpRtti.EnumName + ', '; Continue; end; @@ -738,6 +761,7 @@ function TSimpleRTTI.Param (var aParam : String) : iSimpleRTTI; finally aParam := Copy(aParam, 0, Length(aParam) - 2) + ' '; ctxRtti.Free; + DictionaryFields.Free; end; end; @@ -804,6 +828,19 @@ function TSimpleRTTI.Update(var aUpdate : String) : iSimpleRTTI; if prpRtti.IsEnum then begin + case prpRtti.PropertyType.TypeKind of + tkInteger, tkInt64, tkFloat: + if prpRtti.GetValue(Pointer(FInstance)).AsInteger = 0 then + Continue; + tkWChar, + tkLString, + tkWString, + tkUString, + tkString: + if prpRtti.GetValue(Pointer(FInstance)).AsString = EmptyStr then + Continue; + end; + aUpdate := aUpdate + prpRtti.FieldName + ' = :' + prpRtti.FieldName + '::' + prpRtti.EnumName + ', '; Continue; end;