In Delphi, I can do this:
Type
TFourCC = Array[0..3] of AnsiChar;
Function Func(Param : TFourCC) : Boolean;
begin
{ ... }
end;
Func('ABCD'); // I can pass this as literal text without problems
Now, I want to make this parameter optional.
Function Func(Param : TFourCC = 'ABCD') : Boolean;
begin
{ ... }
end;
Now, the compiler throws me an error: E2268 Parameters of this type cannot have default values
Ok, so I was thinking overloading the function should do the trick then...
Function Func : Boolean; overload;
begin
{ ... }
end;
Function Func(Param : TFourCC) : Boolean; overload;
begin
{ ... }
end;
Func('ABCD'); // This line that worked in first example now gives an error
Unfortunately, Delphi doesn't like this either. Where it first accepted the parameter as a TFourCC typed variable, it now gives me E2250 There is no overloaded version of 'Func' that can be called with these arguments.
I beg to disagree with what this error tells me, the same thing worked when it wasn't overloaded.
Can someone explain me the logic behind this, and possibly a solution? I'd like to keep the TFourCC as it is (not a string type), it keeps the handling of reading and writing much easier. I rather avoid assigning it to a variable first before passing it, because the function will be used alot..
TFourCCtype you like to keep?