Start New Discussion within our Software Development Community

I got a problem with abit of code and am unable to fix it, i have marked the area that is having the problem with the error message that i get.

procedure TMainForm.Show(s: string);
var
n, n2, n3: integer;
arTemp: TMyArray;
begin
arTemp := TMyArray.Create();
n := InStr(1, s, ':');
if n = 0 then

// this is were the error happens
s := mid(s, n + 1); ** E2064 Left side cannot be assigned to **
//

arTemp.SplitIn(s, ':');
n2 := imgDraw.Canvas.Pen.Color;
n3 := imgDraw.Canvas.Pen.Width;
imgDraw.Canvas.Pen.Color := StrToInt(arTemp.Items[4]);
drawio.Canvas.Pen.Color := StrToInt(arTemp.Items[4]);
imgDraw.Canvas.Pen.Width := StrToInt(arTemp.Items[5]);
drawio.Canvas.Pen.Width := StrToInt(arTemp.Items[5]);
imgDraw.Canvas.MoveTo(StrToInt(arTemp.Items[0]), StrToInt(arTemp.Items[1]));
imgDraw.Canvas.LineTo(StrToInt(arTemp.Items[2]), StrToInt(arTemp.Items[3]));
drawio.Canvas.MoveTo(StrToInt(arTemp.Items[0]), StrToInt(arTemp.Items[1]));
drawio.Canvas.LineTo(StrToInt(arTemp.Items[2]), StrToInt(arTemp.Items[3]));
imgDraw.Canvas.Pen.Color := n2;
imgDraw.Canvas.Pen.Width := n3;
drawio.Canvas.Pen.Color := n2;
drawio.Canvas.Pen.Width := n3;
arTemp.Free();
end;

anyone know what the problem is???

If you want to mutate the string parameter you must declare it var in the procedure's signature:

procedure TMainForm.Show(var s: String);

But a better method would probably be to declare a local variable string to handle your error line, so:

procedure TMainForm.Show(s: string);
var
  n, n2, n3: integer;
  arTemp: TMyArray;
  tempStr: String;
begin
  arTemp := TMyArray.Create();
  n := InStr(1, s, ':');
  if n = 0 then

  tempStr := mid(s, n + 1);
  arTemp.SplitIn(tempStr, ':');
  //...
end;
This question has already been answered. Start a new discussion instead.