Recent

Author Topic: [ok] is it possible to default value for a parameter of type 'array of const' ?  (Read 446 times)

CapelliC

  • Jr. Member
  • **
  • Posts: 58
Since I use frequently the following pattern, I wonder if is there a way to declare a default value for a parameter of type 'array of const' as empty:

Code: Pascal  [Select][+][-]
  1. program x_array_of_const_default;
  2.  
  3. uses SysUtils;
  4.  
  5. {$if 0}
  6. procedure test(const msg: string);
  7. begin
  8.   writeln(msg)
  9. end;
  10. procedure test(const msg: string; const args: array of const);
  11. begin
  12.   test(format(msg, args))
  13. end;
  14. {$else}
  15. procedure test(const msg: string; const args: array of const = []);
  16. begin
  17.   writeln(format(msg, args))
  18. end;
  19. {$endif}
  20. begin
  21.   test('hello %s!', ['world']);
  22.   test('hello all!')
  23. end.
  24.  
  25.  

I realize could be impossible to avoid the error message (x_array_of_const_default.lpr(15,62) Fatal: Syntax error, ")" expected but "=" found), but I'd like to know from more knowledgeable people...

Thanks, Carlo
« Last Edit: October 27, 2020, 04:10:50 pm by CapelliC »

egsuh

  • Hero Member
  • *****
  • Posts: 504

Well you have to use overload, I guess.

Thaddy

  • Hero Member
  • *****
  • Posts: 10573
varargs misuse will do that.

jamie

  • Hero Member
  • *****
  • Posts: 3791
That would be a nice feature..

but not sure exactly how that would look in a complex manner.


(a:Arary of const = ['hi',45,23,'done']);
(:a:array of byte = [1,2,3,4];);

Maybe we'll see this in the future
The only true wisdom is knowing you know nothing

PascalDragon

  • Hero Member
  • *****
  • Posts: 2418
  • Compiler Developer
Since I use frequently the following pattern, I wonder if is there a way to declare a default value for a parameter of type 'array of const' as empty:

No, there is not.

CapelliC

  • Jr. Member
  • **
  • Posts: 58
Thanks you all for your answers. Appreciated.

 

TinyPortal © 2005-2018