title: Dynamic TImage's in dynamic TPanel's?
body: <p>OK, I'm trying to create some custom number of TPanel's at runtime on TScrollBox surface like you can see on following image.</p>
  
  <p><img src="https://i.stack.imgur.com/xnZdZ.jpg" alt="enter image description here"></p>
  
  <p>To get this I'm using following code and that works fine.</p>
  
  <pre><code>var
    pan: array of TPanel;
    maxp, i, x, y: Integer;
  
  ...
  
  maxp := 10;
  SetLength(pan, maxp);
  
  for i := 1 to maxp do begin
    // x is correct value; doesn't cause problem
    // y is correct value; doesn't cause problem
    pan[i-1] := TPanel.Create(form1);
    with pan[i-1] do begin
      Width := 100;
      Height := 150;
      Top := x * 151;
      Left := y * 101;
      Parent := ScrollBox1;
      end;
    end;
  </code></pre>
  
  <p>Now, I have problems to put TImage object in every TPanel with same index (img[0] -> pan[0], img[1] -> pan[1], etc). Look at the following image:</p>
  
  <p><img src="https://i.stack.imgur.com/1znSc.jpg" alt="enter image description here"></p>
  
  <p>Using same logic, I've tried to create TImage's but w/ no success.</p>
  
  <p>I'm using this code and cant figure out what's wrong. It looks so simple to me, but somehow it doesn't provide expected effect.</p>
  
  <pre><code>var
    pan: array of TPanel;
    img: array of TImage;
    maxp, i, x, y: Integer;
  
  ...
  
  maxp := 10;
  SetLength(pan, maxp);
  SetLength(img, maxp);
  
  for i := 1 to maxp do begin
    // x is correct value; doesn't cause problem
    // y is correct value; doesn't cause problem
    pan[i-1] := TPanel.Create(form1);
    with pan[i-1] do begin
      Width := 100;
      Height := 150;
      Top := x * 151;
      Left := y * 101;
      Parent := ScrollBox1;
      end;
    img[i-1] := TImage.Create(form1);
    with img[i-1] do begin
      Width := 98;
      Left := 1;
      Height := 148;
      Top := 1;
      // in original code next line had img[0]. which caused problem
      Picture.LoadFromFile('some_image_file');
      Parent := pan[i-1];
      end;
    end;
  </code></pre>
  
  <p>Somehow it places all TImage objects on same place in first TPanel (pan[0]). It's confusing for me because it says <code>Parent := pan[i-1];</code> but for some reason it always puts TImage in pan[0]. I've tried using breakpoints to see what's going on after every for-loop cycle (added Application.ProcessMessages at the end) and it really creates 10 different images but puts them onto pan[0]. Of course, at the end it shows just last image loaded into pan[0].</p>
  
  <p>My question is how to make one dynamic TImage per dynamic TPanel (with same array indices)?</p>
  
  <p><strong>SOLVED!</strong></p>