I am learning Delphi since the beginning of this week and I am currently reading the Delphi 7 - Developer's Guide
. In this book (Chapter 5-37), the author declares a function as follow:
function FromEuro(const AValue: Double, Factor; FRound: TRoundToRange): Double;
If I had to write this function, I would have written it as follow:
function FromEuro(const AValue, Factor: Double; FRound: TRoundToRange): Double;
My question is : Is there any difference between those declarations ?
What I think you meant to ask is what is the difference between these two:
function FromEuro(const AValue: Double; Factor: Double): Double;
function FromEuro(const AValue, Factor: Double): Double;
The second variant is a contraction that expands to:
function FromEuro(const AValue: Double; const Factor: Double): Double;
And this differs from
function FromEuro(const AValue: Double; Factor: Double): Double;
by way of the second parameter being const
.
Note that I removed the final parameter since it is not relevant to the question.
The documentation says:
A parameter list is a sequence of parameter declarations separated by semicolons and enclosed in parentheses. Each declaration is a comma-delimited series of parameter names, followed in most cases by a colon and a type identifier, and in some cases by the = symbol and a default value.
What the documentation doesn't mention is that each of the parameters in a comma-delimited series of parameter names has the same type. I guess this is meant to be obvious, and it does follow the example set by variable declarations. The documentation for variables says:
The basic syntax for a variable declaration is:
var identifierList:type;
where identifierList is a comma-delimited list of valid identifiers and type is any valid type. For example:
var I: Integer;
declares a variable I of type Integer, while:
var X, Y: Real;
declares two variables - X and Y - of type Real.
On the other hand, perhaps you know all of this already, and all that we have is a typo in a book! And indeed that seems to be the case because the exact same typo can be found here: http://docwiki.embarcadero.com/RADStudio/en/Using_a_Class_to_Manage_Conversions