Delphi: creating and displaying TImage in FormCreate

Being a complete beginner, I just answered the first question ( Delphi: TImage.Create causes an access violation ) to immediately fix 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 show this form

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

Images are not visible. What am I doing wrong?

I want to thank everyone for their advice. I hope asking elementary questions will help others avoid them in the future :-)

+4
source share
2 answers

Set the Parent property of all image components in 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; 
+12
source

Well, I suppose you need to add individual TImage components to the checklist of the current form?

This means: just because you create TImage code in the code does not mean that it is actually added to form controls. You will have to do this in code - however, I have not touched Delphi in a couple of years, so I cannot provide any code right now.

+1
source

Source: https://habr.com/ru/post/1286666/


All Articles