Book a Demo

Author Topic: constructors in delphi  (Read 4380 times)

StefanR

  • EA Novice
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
constructors in delphi
« on: May 24, 2004, 08:10:21 am »
I'm using EA to generate Delphi-code from UML-class-models. However, when overloading constructors in a diagram the generated code looks like this:

type MyClass = class
 constructor Create; overload;
 procedure Create(param1: String); overload;
end;

Any suggestion for having two constructor-declarations?

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: constructors in delphi
« Reply #1 on: May 25, 2004, 11:10:01 pm »
Hi StefanR,

I don't really know Delphi, so forgive me if I don't get all of your problem.  The problem that I can see that you have is that the second one has "procedure" instead of constructor.  This can be fixed by making the following change to both the Operation Declaration and Operation Declaration Impl templates.

This:
Code: [Select]
%if opReturnType == "" or opReturnType == "void"%
$op_type = "procedure"
%else%
$op_type = "function"
%endIf%

Becomes:
Code: [Select]
%if opName == "Create"%
$op_type = "constructor"
%else if opReturnType == "" or opReturnType == "void"%
$op_type = "procedure"
%else%
$op_type = "function"
%endIf%


Now because I don't know Delphi very well I don't know if the "overload" should be there or not.  If you tell me that I've got this right then I could change the default template for the next build of EA.

Simon

StefanR

  • EA Novice
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
Re: constructors in delphi
« Reply #2 on: May 26, 2004, 12:12:17 am »
Hi Simon,
thanks for your reply. It works and you are right when you suppose that 'overload' has to succeed both constructor declarations.

Can you please post which lines have to be changed?

There's another small bug for default-values in parameters. I tried hard and finally managed to find the incorrect lines: In Parameters section

Code: [Select]
%if paramDefault != "" and paramDefault != "<none>"%
" = " value


becomes

Code: [Select]
%if paramDefault != "" and paramDefault != "<none>"%
= %paramDefault%


It works for me in one case, but I'm not sure, if its a 'global solution' for alle parameter types... I have my doubts because the parameter-section looks different in other languages like C++, etc.

Maybe you can verify this?
Stefan.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: constructors in delphi
« Reply #3 on: May 27, 2004, 04:16:45 pm »
Hi Stephan,

That looks right.  It certainly shouldn't have been what it was.  The %paramDefault% corresponds to the string in the default field in the parameters tab of the operation menu.

I'll make the fix for that too.

Thanks, it makes my job easy when someone reporting a bug also tell me exactly how to fix it.  :)

Simon

StefanR

  • EA Novice
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
Re: constructors in delphi
« Reply #4 on: May 28, 2004, 04:54:51 am »
Hello Simon,

unfortunately there seems to be a bug in your first solution: when exchanging the lines as you proposed, no code for Delphi-'function's is generated.

In fact, each operation becomes a 'procedure', no matter what return-type has been declared. Any suggestion???

Thanks in advance,
Stefan.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: constructors in delphi
« Reply #5 on: May 30, 2004, 04:52:12 pm »
Sorry, "else if" doesn't work.  It should be "elseIf".  :-[

I'll fix that up.