void generate_delphi_struct_writer_impl(ostream& out, std::string cls_prefix, t_struct* tstruct, bool is_exception);
void generate_delphi_struct_result_writer_impl(ostream& out, std::string cls_prefix, t_struct* tstruct, bool is_exception);
- void generate_delphi_struct_tostring_impl(ostream& out, std::string cls_prefix, t_struct* tstruct, bool is_exception);
+ void generate_delphi_struct_tostring_impl(ostream& out, std::string cls_prefix, t_struct* tstruct, bool is_exception, bool is_x_factory);
void add_delphi_uses_list( string unitname);
} else {
generate_delphi_struct_writer_impl( out, cls_prefix, tstruct, is_exception);
}
- generate_delphi_struct_tostring_impl( out, cls_prefix, tstruct, is_exception);
}
+ generate_delphi_struct_tostring_impl( out, cls_prefix, tstruct, is_exception, is_x_factory);
if (is_exception && is_x_factory) {
generate_delphi_create_exception_impl( out, cls_prefix, tstruct, is_exception);
indent(out) << "constructor Create;" << endl;
indent(out) << "destructor Destroy; override;" << endl;
- if ((! is_exception) || is_x_factory) {
- out << endl;
- indent(out) << "function ToString: string; override;" << endl;
- }
+ out << endl;
+ indent(out) << "function ToString: string; override;" << endl;
if (is_exception && (! is_x_factory)) {
out << endl;
indent_impl(out) << "end;" << endl;
}
+ indent_impl(out) << "Result.UpdateMessageProperty;" << endl;
+
indent_down_impl();
indent_impl(out) << "end;" << endl << endl;
}
}
-void t_delphi_generator::generate_delphi_struct_tostring_impl(ostream& out, string cls_prefix, t_struct* tstruct, bool is_exception) {
+void t_delphi_generator::generate_delphi_struct_tostring_impl(ostream& out, string cls_prefix, t_struct* tstruct, bool is_exception, bool is_x_factory) {
const vector<t_field*>& fields = tstruct->get_members();
vector<t_field*>::const_iterator f_iter;
string cls_nm;
if (is_exception) {
- cls_nm = type_name(tstruct,true,false,true,true);
+ cls_nm = type_name(tstruct,true,(! is_x_factory),is_x_factory,true);
} else {
cls_nm = type_name(tstruct,true,false);
}
// base class for IDL-generated exceptions
TException = class( SysUtils.Exception)
public
- procedure Message; // hide inherited property to prevent accidental read/write
+ function Message : string; // hide inherited property: allow read, but prevent accidental writes
+ procedure UpdateMessageProperty; // update inherited message property with toString()
end;
implementation
{ TException }
-procedure TException.Message;
-// hide inherited property to prevent accidental read/write
+function TException.Message;
+// allow read (exception summary), but prevent accidental writes
+// read will return the exception summary
begin
- ASSERT( FALSE, 'Unexpected call to '+ClassName+'.message. Forgot the underscore?');
+ result := Self.ToString;
+end;
+
+procedure TException.UpdateMessageProperty;
+// Update the inherited Message property to better conform to standard behaviour.
+// Nice benefit: The IDE is now able to show the exception message again.
+begin
+ inherited Message := Self.ToString; // produces a summary text
end;
{ TApplicationException }