[solved] how to access variable names by number lazarus / 21-General ---------------------------------------------------------------------- Muso · 2021-04-18 17:41 This is propably a noob question but googling around did not help me: I have to parse a text file with one line. The line contains a comma separated list of values and each value has to be stored into a new variable. So what I am looking for is a for loop that reads out a value, created a new variable and assign it. So something in this form: 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   posPrevInt:= 0;  counterInt:= 1;  for i:= 1 to 16 do  begin   posCurrInt:= Pos(',', ReadString, posPrevInt);   DummyString:= Copy(ReadLine, posPrevInt, posCurrInt- posPrevInt);   if not TryStrToFloat(DummyString, Gain1) then    exit;   posCommaPrev:= posCommaCurr;   inc(counterInt);  end; Instead of "Gain1" I want to assign the variables Gain1, then Gain2, then Gain3,... So is there a way to declare the variable name using a number like "Gain+posPrevInt:= " or having the variables in an array to access them? ---------------------------------------------------------------------- wp · 2021-04-18 17:51 The easiest way to split a comma-separated list into an array is by using the Split string helper (untested): 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  TFloatArray: array of Double; function GetGains(AString: String; out Gains: TFloatArray): Boolean;var  sa: TStringArray;  i: Integer;begin  sa := AString.Split(',');  SetLength(Gains,Length(sa));  for i := 0 to High(sa) do    if not TryStrToFloat(sa[i], Gains[i]) then    begin    Gains := nil;      Result := false;      exit;    end;  Result := true;end; ---------------------------------------------------------------------- Muso · 2021-04-18 19:06 Quote from: wp on April 18, 2021, 07:51:59 pmThe easiest way to split a comma-separated list into an array is by using the Split string helper (untested): Many thanks, works like a charm.