基本上,我有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
任何帮助或甚至其他方式来实现这一目标都会有所帮助。
答案 0 :(得分:1)
FindComponent()
返回TComponent
,而Parent
属性则需要TWinControl
。假设FindComponent()
正在返回正确的组件,只需键入它:
imgPanel.Parent := TWinControl(cPanel);