2

would like to use the same name for a procedure and a function , can I do this, any regulations on this issue ?

 /// first version 
 function RunMyImageProcess (aRect : TRect; aBitmap : TBitmap ):  TPoint; overload ;

 ///  a overload version, this works  , it is simple :-) 
 function RunMyImageProcess (aRect : TRect; aBitmap : TBitmap ; aprocessflag : Boolean):  TPoint; overload ; 

 ///  need now a procedure
 ///  will return 2 Points now !!!
 ///   can I do this in DELPHI ???? 
 procedure RunMyImageProcess (var LowerLeft, Upperright: TPoint; aBitmap : TBitmap ; aprocessflag : Boolean):  boolean; overload ;
4

1 回答 1

9

You can have overloaded functions and procedures with the same name.

However, you cannot rely on function return type for overload discrimination. So if you have a function and a procedure with the same argument list, they cannot be overloaded.

I would caution you not to go mad with overloading. There are all sorts of traps that you can fall into. For example, if you distinguish based on floating point or integer arguments it can be hard to be sure which overload you are calling. There is also much scope for confusion when you distinguish between pointers and dynamic arrays, as Embarcadero discovered with the XE3 TStream overloads.

In fact the documentation of the overloading rules is incomplete and the only way to fully understand the compiler's behaviour is by reverse engineering.

于 2013-03-29T22:52:11.553 回答