Passing an open typed array as a parameter lazarus / 62-General ---------------------------------------------------------------------- Bazzao · 2019-02-20 09:03 I'm trying to teach myself how to pass, as a parameter, a open-ended typed array. I get the message: Error: Incompatible type for arg no. 3: Got "{Array Of Const/Constant Open} Array of Constant String", expected "TStrIntRecArr" 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  TStrIntRec=record    rStr:string;    rInt:integer;  end;  TStrIntRecArr=array of TStrIntRec; procedure ShowDebug(pMode:integer; pTit:string; const pArr:TStrIntRecArr);var I,K,L:integer; S,T:string;begin  K:=0;  for I:=Low(pArr) to High(pArr) do    begin    S:=pArr[I].rStr;      L:=length(S);      if L>K then K:=L;    end;  T:=pTit+':||';  for I:=Low(pArr) to High(pArr) do    if pMode=3 then    T:=T+IntToStr(pArr[I].rInt)+'='+pArr[I].rStr+'||'    else    if pMode=2 then      begin        S:=copy(pArr[I].rStr+'        ',1,K);      T:=T+S+'='+IntToStr(pArr[I].rInt)+'||';      end    else      T:=T+pArr[I].rStr+'||';  T:=StringReplace(T,'||',#13#10,[rfReplaceAll,rfIgnoreCase]);  ShowMessage(T);end; procedure TForm1.Button1Click(Sender: TObject);begin  ShowDebug(1,'Mode 1',['One',1,'Two',2,'Three',3]);  ShowDebug(2,'Mode 2',['One',1,'Two',2,'Three',3]);  ShowDebug(3,'Mode 3',['One',1,'Two',2,'Three',3]);end;  TIA, Bazza ---------------------------------------------------------------------- Pascal · 2019-02-20 10:39 You did not pass on array of TStrIntRec! Instead you pass a const array of const (...; const Args : Array of const; ...) What is your intention? Passing like you did or passing records? You should have a look at SysUtils.Format if your intention is to pass all values as you did. ---------------------------------------------------------------------- Bazzao · 2019-02-20 11:30 Hi Pascal, Thanks for replying. The object is to pass constants & variables, not all constants. I just wanted to get the structure correct. A previous working version of this I had the strings & integers in two separate arrays, but thought I could create a record and pass it that way. I tried passing an array of TStrIntRec, but the same error came up. Bazza ---------------------------------------------------------------------- Pascal · 2019-02-20 11:47 The problem is that you did not do what you defined! You pass discrete values and not records. You can do it that way, no problem, but then you have to define it this way: 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 ShowDebug(pMode:integer; pTit:string; const pArr : Array of const); Then you have to take care that you get pairs of strings and integers. ---------------------------------------------------------------------- howardpc · 2019-02-20 13:40 When using the array of const syntax you are restricted to the (simple) types supported by TVarRec, which excludes any type of record. Because of the many string types Pascal supports, it is somewhat more involved than you might think to parse an array of const which includes strings. I think what you are looking for is something like the following 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 ShowDebug(aMode: Integer; aTitle: String; anArr: array of const); implementation uses strutils; procedure ShowDebug(aMode: Integer; aTitle: String; anArr: array of const);   function GetNextString(anIdx: Integer; out OK: Boolean): String;  begin    OK := False;    if anIdx >= High(anArr) then      Exit('');    case anArr[anIdx].VType of      vtAnsiString: Result := AnsiString(anArr[anIdx].VAnsiString);      vtChar:       Result := anArr[anIdx].VChar;      vtPChar:      Result := anArr[anIdx].VPChar;      vtPWideChar:  Result := anArr[anIdx].VPWideChar;      vtString:   Result := anArr[anIdx].VString^;      vtWideChar:   Result := AnsiString(anArr[anIdx].VWideChar);      vtWidestring: Result := AnsiString(WideString(anArr[anIdx].VWideString));      else Exit('');    end;    OK := True;  end; var  i: Integer;  maxLen: Integer = 0;  isOK: Boolean;  msg, s, st: String;  sArr: array of String;begin  msg := aTitle + #10;  i := Low(anArr);  SetLength(sArr, 0);  while i < High(anArr) do    begin      s := GetNextString(i, isOK);      if not isOK then        Inc(i)      else        begin          if Length(s) > maxLen then            maxLen := Length(s);          Inc(i);          if anArr[i].VType = vtInteger then begin            case aMode of            1: msg := msg + s + #10;              2: begin                 SetLength(sArr, Length(sArr)+1);                   sArr[High(sArr)] := s;                 end;              3: msg := msg + IntToStr(anArr[i].VInteger) + ' = ' + s + #10;              else msg := '';            end;            Inc(i);          end;        end;  end;  case isOK of    True: begin            if (aMode = 2) then            begin                s := '';                Inc(maxLen);              for st in sArr do                  s := s + PadLeft(st, maxLen) + #10;                msg := msg + s;              end;          case (msg = '') of              True:  ShowMessage('Error in parsing parameters');              False: ShowMessage(msg);          end;          end;    False: ShowMessage('Error in parsing parameters');  end;end; procedure TForm1.Button1Click(Sender: TObject);begin  ShowDebug(1,'Mode 1',['One',1,'Two',2,'Three',3]);  ShowDebug(2,'Mode 2',['One',1,'Two',2,'Three',3]);  ShowDebug(3,'Mode 3',['One',1,'Two',2,'Three',3]);  ShowDebug(3,'Mode 3',[9,'nine']);end; ---------------------------------------------------------------------- Bazzao · 2019-02-24 23:22 Many thanks Pascal & Howardpc. Got it. Sometimes Pascal (the language) wasn't made to be easy. B