diff --git a/compiler/cpp/src/thrift/generate/t_delphi_generator.cc b/compiler/cpp/src/thrift/generate/t_delphi_generator.cc index 02dca77dc6..607d6173a0 100644 --- a/compiler/cpp/src/thrift/generate/t_delphi_generator.cc +++ b/compiler/cpp/src/thrift/generate/t_delphi_generator.cc @@ -1714,14 +1714,6 @@ void t_delphi_generator::generate_delphi_struct_definition(ostream& out, generate_delphi_property_writer_definition(out, *m_iter, false); } - /* - if (is_x_factory) { - out << '\n'; - indent(out) << "// Create Exception Object" << '\n'; - indent(out) << "function CreateException: " << type_name(tstruct, true, true) << ";" << '\n'; - } - */ - if (members.size() > 0) { out << '\n'; for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) { @@ -1858,40 +1850,9 @@ void t_delphi_generator::generate_delphi_exception_definition(ostream& out, } out << "class(TException, IInterface, IBase, ISupportsToString)" << '\n'; - /* - indent(out) << "public" << '\n'; - indent_up(); - indent(out) << "type" << '\n'; - indent_up(); - generate_delphi_struct_definition(out, tstruct, is_exception, is_result, true); - indent_down(); - indent_down(); - */ - indent(out) << "private" << '\n'; indent_up(); indent(out) << "FData : " << struct_intf_name << ';' << '\n'; - - // weg - indent(out) << "{" << '\n'; - - for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) { - indent(out) << declare_field(*m_iter, false, "F", true) << '\n'; - } - - if (members.size() > 0) { - indent(out) << '\n'; - for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) { - if ((*m_iter)->get_req() != t_field::T_REQUIRED) { - isset_name = prop_name(*m_iter, true, "F__isset_"); - indent(out) << isset_name << ": System.Boolean;" << '\n'; - } - } - } - - // weg - indent(out) << "}" << '\n'; - indent(out) << '\n'; for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) { @@ -1935,6 +1896,7 @@ void t_delphi_generator::generate_delphi_exception_definition(ostream& out, indent(out) << "destructor Destroy; override;" << '\n'; out << '\n'; + indent(out) << "property ExceptionData : " << struct_intf_name << " read FData;" << '\n'; indent(out) << "function ToString: string; override;" << '\n'; out << '\n'; @@ -1942,12 +1904,6 @@ void t_delphi_generator::generate_delphi_exception_definition(ostream& out, indent(out) << "procedure Read( const iprot: IProtocol);" << '\n'; indent(out) << "procedure Write( const oprot: IProtocol);" << '\n'; - /* - out << '\n'; - indent(out) << "// Create Exception Object" << '\n'; - indent(out) << "function CreateException: " << type_name(tstruct, true, true) << ";" << '\n'; - */ - if (members.size() > 0) { out << '\n'; indent(out) << "// Properties" << '\n'; @@ -2641,7 +2597,7 @@ void t_delphi_generator::generate_process_function(t_service* tservice, t_functi indent_up_impl(); if (!tfunction->is_oneway()) { string factory_name = normalize_clsnm((*x_iter)->get_type()->get_name(), "", true) + "Factory"; - indent_impl(s_service_impl) << "ret." << prop_name(*x_iter) << " := E." << factory_name << ";" + indent_impl(s_service_impl) << "ret." << prop_name(*x_iter) << " := E.ExceptionData;" << '\n'; } indent_down_impl(); @@ -3563,8 +3519,7 @@ void t_delphi_generator::generate_delphi_clear_union_value(ostream& out, t_type* ftype = tfield->get_type(); bool is_xception = ftype->is_xception(); - indent_impl(out) << "if " << prop_name(tfield, is_xception_class,"F__isset_") << " then begin" - << '\n'; + indent_impl(out) << "if " << prop_name(tfield, is_xception_class,"F__isset_") << " then begin" << '\n'; indent_up_impl(); indent_impl(out) << prop_name(tfield, is_xception_class,"F__isset_") << " := False;" << '\n'; indent_impl(out) << prop_name(tfield, is_xception_class,fieldPrefix) << " := " @@ -3591,7 +3546,7 @@ void t_delphi_generator::generate_delphi_property_writer_impl(ostream& out, indent_impl(out) << "procedure " << cls_prefix << name << "." << prop_name(tfield, is_xception_class,"Set") - << "( const Value: " << type_name(ftype, false, true, is_xception, true) << ");" + << "( const Value: " << type_name(ftype, false, true, false, false) << ");" << '\n'; indent_impl(out) << "begin" << '\n'; indent_up_impl(); @@ -3625,7 +3580,7 @@ void t_delphi_generator::generate_delphi_property_reader_impl(ostream& out, indent_impl(out) << "function " << cls_prefix << name << "." << prop_name(tfield, is_xception_class,"Get") << ": " - << type_name(ftype, false, true, is_xception, true) << ";" << '\n'; + << type_name(ftype, false, true, false, false) << ";" << '\n'; indent_impl(out) << "begin" << '\n'; indent_up_impl(); if(is_xception_class) { @@ -3681,41 +3636,6 @@ void t_delphi_generator::generate_delphi_create_exception_impl(ostream& out, string exception_cls_nm = type_name(tstruct, true, true); string cls_nm = type_name(tstruct, true, false, is_exception, is_exception); - - /* - indent_impl(out) << "function " << cls_nm << ".CreateException: " << exception_cls_nm << ";" - << '\n'; - - indent_impl(out) << "begin" << '\n'; - indent_up_impl(); - - indent_impl(out) << "Result := " << exception_cls_nm << ".Create;" << '\n'; - string factory_name = normalize_clsnm(tstruct->get_name(), "", true) + "Factory"; - indent_impl(out) << "Result.F" << factory_name << " := Self;" << '\n'; - - const vector& fields = tstruct->get_members(); - vector::const_iterator f_iter; - - string propname; - - for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) { - propname = prop_name(*f_iter, is_exception); - if ((*f_iter)->get_req() != t_field::T_REQUIRED) { - indent_impl(out) << "if " << prop_name(*f_iter, is_exception,"__isset_") << " then begin" << '\n'; - indent_up_impl(); - } - indent_impl(out) << "Result." << propname << " := " << propname << ";" << '\n'; - if ((*f_iter)->get_req() != t_field::T_REQUIRED) { - indent_down_impl(); - indent_impl(out) << "end;" << '\n'; - } - } - - indent_impl(out) << "Result.UpdateMessageProperty;" << '\n'; - - indent_down_impl(); - indent_impl(out) << "end;" << '\n' << '\n'; - */ } void t_delphi_generator::generate_delphi_struct_reader_impl(ostream& out, @@ -3853,8 +3773,7 @@ void t_delphi_generator::generate_delphi_struct_reader_impl(ostream& out, cls_nm = type_name(tstruct, true, is_exception && (!is_x_factory), is_x_factory, is_x_factory); - indent_impl(out) << "procedure " << cls_prefix << cls_nm << ".Read( const iprot: IProtocol);" - << '\n'; + indent_impl(out) << "procedure " << cls_prefix << cls_nm << ".Read( const iprot: IProtocol);" << '\n'; indent_impl(out) << "var" << '\n'; indent_up_impl(); indent_impl(out) << "field_ : TThriftField;" << '\n'; diff --git a/lib/delphi/test/serializer/SerializerData.dpr b/lib/delphi/test/serializer/SerializerData.dpr index 5166807ab3..637e4ed992 100644 --- a/lib/delphi/test/serializer/SerializerData.dpr +++ b/lib/delphi/test/serializer/SerializerData.dpr @@ -38,10 +38,10 @@ uses Thrift.Stream in '..\..\src\Thrift.Stream.pas', Thrift.WinHTTP in '..\..\src\Thrift.WinHTTP.pas', Thrift.TypeRegistry in '..\..\src\Thrift.TypeRegistry.pas', - Exceptions in 'gen-delphi\Exceptions.pas', System_ in 'gen-delphi\System_.pas', SysUtils_ in 'gen-delphi\SysUtils_.pas', test.ExceptionStruct in 'gen-delphi\test.ExceptionStruct.pas', + test.SimpleException in 'gen-delphi\test.SimpleException.pas', DebugProtoTest in 'gen-delphi\DebugProtoTest.pas', TestSerializer.Data in 'TestSerializer.Data.pas'; @@ -88,7 +88,7 @@ exports CreateNesting, CreateHolyMoley, CreateCompactProtoTestStruct, - CreateBatchGetResponse; + CreateBatchGetResponse, CreateSimpleException; diff --git a/lib/delphi/test/serializer/SerializerData.dproj b/lib/delphi/test/serializer/SerializerData.dproj index eba8f17ca6..cdad312051 100644 --- a/lib/delphi/test/serializer/SerializerData.dproj +++ b/lib/delphi/test/serializer/SerializerData.dproj @@ -65,10 +65,10 @@ - + @@ -89,7 +89,7 @@ +thrift.exe -r -gen delphi:com_types SimpleException.thrift]]> Delphi.Personality.12 @@ -126,6 +126,9 @@ thrift.exe -r -gen delphi:com_types Exceptions.thrift]]> SerializerData.dpr + + bin\Debug\Win32\TestSerializer.exe + True diff --git a/lib/delphi/test/serializer/Exceptions.thrift b/lib/delphi/test/serializer/SimpleException.thrift similarity index 96% rename from lib/delphi/test/serializer/Exceptions.thrift rename to lib/delphi/test/serializer/SimpleException.thrift index ff0dbf8261..6458fa6266 100644 --- a/lib/delphi/test/serializer/Exceptions.thrift +++ b/lib/delphi/test/serializer/SimpleException.thrift @@ -17,6 +17,8 @@ * under the License. */ +namespace * test.SimpleException + exception Error { 1: i32 ErrorCode 2: Error InnerException diff --git a/lib/delphi/test/serializer/TestSerializer.Data.pas b/lib/delphi/test/serializer/TestSerializer.Data.pas index 65f44c6d14..c2aaad4b18 100644 --- a/lib/delphi/test/serializer/TestSerializer.Data.pas +++ b/lib/delphi/test/serializer/TestSerializer.Data.pas @@ -28,7 +28,7 @@ interface Thrift.Protocol, Thrift.Collections, test.ExceptionStruct, - Exceptions, + test.SimpleException, DebugProtoTest; @@ -374,7 +374,7 @@ class function Fixtures.CreateBatchGetResponse : IBatchGetResponse; data.Id := REQUEST_ID; data.Data := TThriftBytesImpl.Create( TEncoding.UTF8.GetBytes( #0#1#2#3#4#5#6#7#8)); - error := TSomeException.Create; + error := TSomeExceptionImpl.Create; error.Error := TErrorCode.GenericError; result := TBatchGetResponseImpl.Create; @@ -394,7 +394,7 @@ class function Fixtures.CreateSimpleException : IError; inner := result; result := TErrorImpl.Create; result.ErrorCode := i; - result.InnerException_ := inner; + result.InnerException := inner; end; end; diff --git a/lib/delphi/test/serializer/TestSerializer.Tests.pas b/lib/delphi/test/serializer/TestSerializer.Tests.pas index 452a4dab1c..7e9d5b9cad 100644 --- a/lib/delphi/test/serializer/TestSerializer.Tests.pas +++ b/lib/delphi/test/serializer/TestSerializer.Tests.pas @@ -42,7 +42,7 @@ interface Thrift.TypeRegistry, System_, test.ExceptionStruct, - Exceptions, + test.SimpleException, DebugProtoTest; {$TYPEINFO ON} @@ -346,7 +346,7 @@ procedure TTestSerializer.Test_SimpleException( const method : TMethod; const fa end; // init + read - correct := TBatchGetResponseImpl.Create; + correct := TErrorImpl.Create; case method of mt_Bytes: Deserialize( bytes, tested, factory); mt_Stream: begin @@ -358,27 +358,15 @@ procedure TTestSerializer.Test_SimpleException( const method : TMethod; const fa end; // check - correct := CreateBatchGetResponse; - - // rewrite the following test if not - ASSERT( tested.Responses.Count = 1); - ASSERT( correct.Responses.Count = tested.Responses.Count); - for corrDP in correct.Responses do begin - for testDP in tested.Responses do begin - ASSERT( corrDP.Key = testDP.Key); - ASSERT( corrDP.Value.Id = testDP.Value.Id); - ASSERT( corrDP.Value.Data.Count = testDP.Value.Data.Count); - end; - end; - - // rewrite the following test if not - ASSERT( tested.Errors.Count = 1); - ASSERT( correct.Errors.Count = tested.Errors.Count); - for corrEP in correct.Errors do begin - for testEP in tested.Errors do begin - ASSERT( corrEP.Key = testEP.Key); - ASSERT( corrEP.Value.Error = testEP.Value.Error); - end; + correct := CreateSimpleException; + while correct <> nil do begin + // validate + ASSERT( correct.ErrorCode = tested.ErrorCode); + + // iterate + correct := correct.InnerException; + tested := tested.InnerException; + ASSERT( (tested <> nil) xor (correct = nil)); // both or none end; end; @@ -399,6 +387,7 @@ procedure TTestSerializer.Test_Serializer_Deserializer; Test_OneOfEach( method, factory, stream); Test_CompactStruct( method, factory, stream); Test_ExceptionStruct( method, factory, stream); + Test_SimpleException( method, factory, stream); end; Writeln; diff --git a/lib/delphi/test/serializer/TestSerializer.dpr b/lib/delphi/test/serializer/TestSerializer.dpr index b07127b2b5..8c2f64d9e1 100644 --- a/lib/delphi/test/serializer/TestSerializer.dpr +++ b/lib/delphi/test/serializer/TestSerializer.dpr @@ -44,8 +44,8 @@ uses System_ in 'gen-delphi\System_.pas', SysUtils_ in 'gen-delphi\SysUtils_.pas', DebugProtoTest in 'gen-delphi\DebugProtoTest.pas', - Exceptions in 'gen-delphi\Exceptions.pas', test.ExceptionStruct in 'gen-delphi\test.ExceptionStruct.pas', + test.SimpleException in 'gen-delphi\test.SimpleException.pas', TestSerializer.Tests in 'TestSerializer.Tests.pas'; diff --git a/lib/delphi/test/serializer/TestSerializer.dproj b/lib/delphi/test/serializer/TestSerializer.dproj index 4d53a9f0ef..5ea2b796ad 100644 --- a/lib/delphi/test/serializer/TestSerializer.dproj +++ b/lib/delphi/test/serializer/TestSerializer.dproj @@ -67,8 +67,8 @@ - + Cfg_2 @@ -88,7 +88,7 @@ +thrift.exe -r -gen delphi:com_types SimpleException.thrift]]> Delphi.Personality.12