0
基本上,我有8個面板,我想通過使用循環爲其中的所有圖片分配一個圖片,以便使用TComponent變量和圖片我在運行時創建的。但我無法找到一種方法來使用此字符串('pnlDisplay'+ inttostr(i))將該圖像分配給父級。 所以我的代碼看起來是這樣的:如何將一個父對象分配給僅使用父對象名稱的對象
var
imgPanel : TImage;
cPanel : TComponent;
begin
for i := 1 to 8 do
begin
cPanel := FindComponent('pnlDisplay' + inttostr(i));
imgPanel := TImage.Create(cPanel);
imgPanel.Parent := cPanel; //Here is my problem
imgPanel.Picture.LoadFromFile('Pic' + inttostr(i) + '.jpg');
imgPanel.Visible := True;
end;
end
任何幫助,甚至另一種方式來實現,這將是有益的。
非常感謝!它現在有效 –