THRIFT-4862 better ToString() support for enums and container types
Client: Delphi
Patch: Jens Geyer
diff --git a/compiler/cpp/src/thrift/generate/t_delphi_generator.cc b/compiler/cpp/src/thrift/generate/t_delphi_generator.cc
index 11501bf..4a2ebda 100644
--- a/compiler/cpp/src/thrift/generate/t_delphi_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_delphi_generator.cc
@@ -3950,7 +3950,7 @@
<< prop_name((*f_iter), is_exception) << ".ToString());" << endl;
} else if (ttype->is_enum()) {
indent_impl(out) << tmp_sb << ".Append(EnumUtils<"
- << type_name(ttype, false, true, is_exception, true)
+ << type_name(ttype, false, true, false, false)
<< ">.ToString( System.Ord( Self."
<< prop_name((*f_iter), is_exception) << ")));" << endl;
} else {
diff --git a/lib/delphi/src/Thrift.Utils.pas b/lib/delphi/src/Thrift.Utils.pas
index 46e238c..11c4f3e 100644
--- a/lib/delphi/src/Thrift.Utils.pas
+++ b/lib/delphi/src/Thrift.Utils.pas
@@ -295,15 +295,18 @@
{ StringUtils<T> }
class function StringUtils<T>.ToString(const value : T) : string;
+type PInterface = ^IInterface;
var pType : PTypeInfo;
- base : ISupportsToString;
+ stos : ISupportsToString;
+ pIntf : PInterface; // Workaround: Rio does not allow the direct typecast
begin
pType := PTypeInfo(TypeInfo(T));
if Assigned(pType) then begin
case pType^.Kind of
tkInterface : begin
- if Supports(IInterface(value), ISupportsToString, base) then begin
- result := base.toString;
+ pIntf := PInterface(@value);
+ if Supports( pIntf^, ISupportsToString, stos) then begin
+ result := stos.toString;
Exit;
end;
end;