简体   繁体   English

TImage数组(Delphi Android)

[英]Array of TImage (Delphi Android)

procedure TForm1.controlClick(Sender: TObject);
var
  i: Integer;
begin
  for i := 2 to Dest.Count-1 do
  begin
    img[i-2].Create(Form1);
    with img[i-2] do begin
      Parent:= Panel1;
      Width:= 100;
      Height:= 150;
      Top:= 10;
      Left:= (i-2)*100;
    end;
  end;
end;

img type is array of TImage, control is a tab. img类型是TImage的数组,控件是一个选项卡。 I want to timages to show like an android gallery. 我想让图像显示得像个Android画廊。 But this gives me an error Access Violation. 但这给我一个错误的访问冲突。

This looks like the classic error in creating an object. 这看起来像创建对象时的经典错误。 Instead of 代替

obj.Create;

you must write: 您必须写:

obj := TSomeClass.Create;

In your case you need to first of all allocate the array: 在您的情况下,您首先需要分配数组:

SetLength(img, Dest.Count-2);

And then in the loop you write: 然后在循环中编写:

img[i-2] := TImage.Create(Form1);

to instantiate the images. 实例化图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM