works it does not have i in it, how can it increase by one as the i increase 1?
I is the loop and increases each time.
You now have currentLeft := currentLeft + 1; so it also increases by 1 each time.
So that works correctly.
Although it's funny... now you have currentLeft which represents the boxnumber in the current row but you have currentTop which you increase by 20 each time. I would either use 1 each time (so you have boxnumber in row and rownumber in currentLeft and currentTop). Or use currentLeft + 30 each time and use real coordinates. Don't mix them.
In your case I would use currenttop:=currenttop+1; and MyBoxes[i].Top := currenttop * 20;
And I would still use currentLeft > 5 check below the box :=.
So something like this: (I'll give complete code now because you already have it too)
const
MaxBoxes = 18;
procedure TForm1.FormCreate(Sender: TObject);
var
i: integer;
currentLeft, currentTop: integer;
begin
currentleft := 1; // initial box-column position
currenttop := 1; // initial box-row position
SetLength(MyBoxes, MaxBoxes);
for i := 0 to MaxBoxes - 1 do // dynamic arrays are 0-based
begin
MyBoxes[i] := TShape.Create(Self);
MyBoxes[i].Parent := Self;
MyBoxes[i].Width := 20;
MyBoxes[i].Height := 10;
MyBoxes[i].Top := 20 { top } + (10 { width } + 10 { space between } ) * currenttop;
MyBoxes[i].Left := 20 { left } + (20 { height } + 5 { space between } ) * currentleft;
MyBoxes[i].Shape := strectangle;
MyBoxes[i].Brush.Color := clGreen;
MyBoxes[i].pen.Color := clGreen;
currentleft := currentleft + 1; // set currentLeft to next box
if currentleft > 5 then // 5 per row
begin
currentleft := 1; // back to first column
currenttop := currenttop + 1; // and next row
end;
end;
end;
You see that initially I set the currentLeft and currentTop to Row 1 and Column 1.
The inside the loop first calculate the Left and Top of your Box.
After that you increase the column (currentLeft) by 1 and see if it exceeds 5.
If it does you reset the column (currentLeft) back to 1 (first column) and increase the row-counter (currentTop).
(Maybe now that you work with row and column-numbers the variables should be currentColumn and currentRow instead of currentLeft and currentRow.)