views:

564

answers:

2

Being quite a newbie, I've just had my first question answered (Delphi: TImage.Create causes Access violation) to immediately bump into a new problem:

procedure TSelectorForm.FormCreate(Sender: TObject);
var
  Loop: Byte;
begin
  for Loop := 1 to 10 do
  begin
    ArrayOfImages[Loop] := TImage.Create(SelectorForm);
    MainForm.MyImageList.GetBitmap(Loop - 1, ArrayOfImages[Loop].Picture.Bitmap);
    ArrayOfImages[Loop].Top := ...
    ArrayOfImages[Loop].Left := ...
    ArrayOfImages[Loop].Enabled := True;
    ArrayOfImages[Loop].Visible := True;
  end;
end;

When I display this form

procedure TMainForm.MyImageClick(Sender: TObject);
begin
  SelectorForm.Visible := True;
end;

the images aren't visible. What am I doing wrong?

I want to thank everyone for their advice. Hopefully, asking elementary questions helps others avoid asking them in future :-)

+9  A: 

Set the Parent property of all image components to the form that contains them.

procedure TSelectorForm.FormCreate(Sender: TObject);
var
  Loop: Byte;
begin
  for Loop := 1 to 10 do
  begin
    ArrayOfImages[Loop] := TImage.Create(SelectorForm);
    MainForm.MyImageList.GetBitmap(Loop - 1, ArrayOfImages[Loop].Picture.Bitmap);
    ArrayOfImages[Loop].Top := ...
    ArrayOfImages[Loop].Left := ...
    ArrayOfImages[Loop].Visible := True;
    ArrayOfImages[Loop].Parent := SelectorForm;
  end;
end;
mghie
+1  A: 

Well, I suppose that you have to add the single TImage components to the control-list of the current form?

That means: just because you're creating a TImage in code does not mean that it is actually added to the form's controls. You'll have to do that in code - however, I've not touched Delphi in a couple of years, so I can't provide any code right now.

Thorsten Dittmar