default values of arrays lazarus / 21-General ---------------------------------------------------------------------- Paolo · 2024-06-01 08:40 Hello (win64, Laz 3.2, FPC 3.2.2) I can do this Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type  TPippa = array of Boolean;....   procedure Pippa(A: integer; B: TPippa = nil);... procedure TForm1.Pippa(A: integer; B: TPippa = nil);begin  if B = nil then    Dothis  else    DoThatend;...procedure TForm1.Button1Click(Sender: TObject);begin  Pippa(10, []);  //<-- DoThis  Pippa(10);       //<-- DoThisend;  I am trying the same with this construct, and this works Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     procedure Pippo(A: integer; B: array of Boolean);... procedure TForm1.Pippo(A: integer; B: array of Boolean);begin  if High(B) < 0 then    DoThis  else    DoThatend;... procedure TForm1.Button1Click(Sender: TObject);begin  Pippo(10, []);  //<-- Do thisend;  but if I try to do as follow it does not compile Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     procedure Pippo(A: integer; B: array of Boolean = []);   I am just trying to understand why open array cannot have default values, that's it thanks. ---------------------------------------------------------------------- cdbc · 2024-06-01 09:53 Hi Forgive me, but isn't this "[]" considered a constructor for dynamic arrays now?!? Regards Benny ---------------------------------------------------------------------- Paolo · 2024-06-01 10:20 what I am trying to do is to have a procedure declaration that accept open array with predefined values so that I can do: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ...Pippo(11, [false, true, false]);  //<-- with some array inputPippo(11);                              //<-- without any array input, in this case the array shoud be empty... ---------------------------------------------------------------------- Thaddy · 2024-06-01 10:24 The difference between an open array parameter of Boolean and a dynamic array of Boolean as usual. People never learn. - Declare a type TBooleanArray=Array of Boolean - You can then do this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type  TBooleanArray=Array of Boolean;procedure TForm1.Pippo(A: integer; B: TBooleanArray = []);Another way is to include the types unit, where that array is predeclared: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses types;procedure TForm1.Pippo(A: integer; B: TBooleanDynArray = []);Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type TBooleanArray = array of Boolean; procedure Pippo(a:integer; const b:TBooleanArray = []);beginend; begin Pippo(11);end. ---------------------------------------------------------------------- paweld · 2024-06-01 10:26 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program Project1; {$mode objfpc}{$H+} procedure Pippo(A: integer; B: array of Boolean);begin  //some codeend; procedure Pippo(A: integer);begin  Pippo(A, []);end; begin  Pippo(1, [True, False]);  Pippo(2);end. ---------------------------------------------------------------------- Paolo · 2024-06-01 10:35 @Thaddy: in my first post already showed what you are suggesting, but I am trying with open array. @paweld: intersting, but this compile without "overload" ? AH, sorry I usually am in {$MODE DELPHI}. Thanks for the suggestions, it can help. but at the end the answer is that is not possible having default values as open array. ---------------------------------------------------------------------- Thaddy · 2024-06-01 11:04 Nope, not for open array parameters. [edit] Even though my example works for an empty typed array (not the open array) there is an issue, that if you assign values in the method declaration it gets picked up by the compiler as a set, which is a bug! I will report that. ---------------------------------------------------------------------- Paolo · 2024-06-01 14:48 I have noticed what you say. in the code in my first post i had to do Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ..procedure Pippa(A: integer; B: TPippa = nil);..Pippa(10, []);  //<-- and this works (B = nil)   but this doesn't compile, with the message you said Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ..procedure Pippa(A: integer; B: TPippa = []);.. ---------------------------------------------------------------------- jamie · 2024-06-02 13:33 From the Rolling stones. "You can't always get what you want"! ---------------------------------------------------------------------- PascalDragon · 2024-06-02 15:13 Quote from: Paolo on June 01, 2024, 10:40:50 amI am just trying to understand why open array cannot have default values, that's it Because an open array parameter just can't.