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 :-)
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;
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With