Mystery solved:
It's not function overloading, function overloading does not yet exist in
Delphi and perhaps for good reason too.
(Actually it does seem to exist somewhat... but then it all goes to
shit/hell... see below lol ***)
The real reason is: the integer version has a parameter and the
double/extended version does not.
(*** One last question which ghosts through my head is: what if the
parameter was optional ? hmmm)
( I explored this question and it's kinda funny a first in my Delphi
history:
[dcc32 Error] TestProgram.dpr(53): E2251 Ambiguous overloaded call to
'MyTest'
TestProgram.dpr(33): Related method: function MyTest: Double;
TestProgram.dpr(39): Related method: function MyTest(Integer): Integer;
)
I will post the secondary code to generate this error below the first
version.
// first version:
// *** Begin of Test Program ***
program TestProgram;
{
Test function overloading.
version 0.01 created on 20 may 2015 by Skybuck Flying
(Cause for this test is "Random" returning integer or double based on
variable which is assigned too.
Conclusion for now:
It does not seem to be function overloading which Random is using.
Thus my initial hunch that this might be compiler magic seems to be
warrented/have some merit.
Apperently the real reason for different versions of random is this:
the integer version is "parameterized", the double/extended version is not.
Which is kinda whacky but ok.
}
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils;
function MyTest : double; overload;
begin
result := 666.666;
end;
{
function MyTest : integer; overload; // *** PROBLEM: identifier redeclared,
perhaps try in a unit ? ***
begin
result := 12345;
end;
}
procedure Main;
var
vInteger : integer;
vDouble : double;
begin
writeln('program started');
{
vInteger := MyTest;
writeln('vInteger: ', vInteger );
}
vDouble := MyTest;
writeln('vDouble: ', vDouble );
vInteger := Random( 5 );
writeln('vInteger: ', vInteger );
vDouble := Random;
writeln('vDouble: ', vDouble );
writeln('program finished');
end;
begin
try
Main;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
ReadLn;
end.
// *** End of Test Program ***
// second version:
// *** Begin of Test Program ***
program TestProgram;
{
Test function overloading.
version 0.01 created on 20 may 2015 by Skybuck Flying
(Cause for this test is "Random" returning integer or double based on
variable which is assigned too.
Conclusion for now:
It does not seem to be function overloading which Random is using.
Thus my initial hunch that this might be compiler magic seems to be
warrented/have some merit.
Apperently the real reason for different versions of random is this:
the integer version is "parameterized", the double/extended version is not.
Which is kinda whacky but ok.
version 0.02 creates:
[dcc32 Error] TestProgram.dpr(53): E2251 Ambiguous overloaded call to
'MyTest'
TestProgram.dpr(33): Related method: function MyTest: Double;
TestProgram.dpr(39): Related method: function MyTest(Integer): Integer;
^^^ A first for me I think... kinda funny ^^^ =D
}
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils;
function MyTest : double; overload;
begin
result := 666.666;
end;
function MyTest( Para : integer = 0 ) : integer; overload; // *** PROBLEM:
identifier redeclared, perhaps try in a unit ? ***
begin
result := 12345;
end;
procedure Main;
var
vInteger : integer;
vDouble : double;
begin
writeln('program started');
vInteger := MyTest;
writeln('vInteger: ', vInteger );
vDouble := MyTest;
writeln('vDouble: ', vDouble );
vInteger := Random( 5 );
writeln('vInteger: ', vInteger );
vDouble := Random;
writeln('vDouble: ', vDouble );
writeln('program finished');
end;
begin
try
Main;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
ReadLn;
end.
// *** End of Test Program ***
Bye,
Skybuck.