Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Looping through an array of strings - Type mismatch

I'm attempting to split a csv string and then loop though the array and alter those string, before building it back into a comma separated string again.

function StrSplit(Text: String; Separator: String): Array of String;
var
  i, p: Integer;
  Dest: Array of String; 
begin
  i := 0;
  repeat
    SetArrayLength(Dest, i+1);
    p := Pos(Separator,Text);
    if p > 0 then begin
      Dest[i] := Copy(Text, 1, p-1);
      Text := Copy(Text, p + Length(Separator), Length(Text));
      i := i + 1;
    end else begin
      Dest[i] := Text;
      Text := '';
    end;
  until Length(Text)=0;
  Result := Dest
end;

function FormatHttpServer(Param: String): String;
var 
build: string;
s: string;
ARRAY1: Array of String;
begin
  ARRAY1 := StrSplit(param, ',');
  build:='';
  for s in ARRAY1 do
  begin
    build := build + DoSomething(C);
  end;
end;

I call the FormatHttpServer from elsewhere. I can't get the script to compile though because on the following line I get a "type mismatch error" and I don't understand why. It should be looping through an array of strings using the string s.

for s in ARRAY1 do
like image 868
dhockey Avatar asked Jun 09 '17 14:06

dhockey


1 Answers

Inno Setup Pascal Script does not support for ... in syntax.

You have to use indexes:

var
  I: Integer;
  A: array of string;
  S: string;
begin
  A := { ... };
  for I := 0 to GetArrayLength(A) - 1 do
  begin
    S := A[I];
    { Do something with S }
  end;
end;
like image 122
Martin Prikryl Avatar answered Nov 15 '22 08:11

Martin Prikryl