使用一组TImage查找特定图像

问题描述 投票:-1回答:2

我有一个VCL表格,左侧面板有24个图像(imA1 .. imA24)的TImage,右面板有30个图像(image25 .. image53)的TImage。所有图像均为100 x 150.这些图像可能会加载宽度为100但高度不同的图片。计划是以这样的方式调整Image.Height和Image.Top,使得所有显示的图片将由Timage帧的底部对齐。由于每个图像将在运行时加载不同的图片,我需要存储Image.Top位置(我有5行左右图片)。我们的想法是通过一个单独的程序来完成。请参阅代码示例。我面临的问题是,显然我使用'set'功能是不正确的,或使用'in'运算符。有人有什么建议吗?谢谢 - 弗雷德(我找到的一个替代方案是将原始顶部位置存储在所有图像的单独记录字段中。也许更容易。但为什么使用'套'不起作用?)

Type
TForm1 = class(Tform)
  imA1    : TImage;  // and all the others to imA24
  image25 : TImage; // etc

Type
  TShow = record
    image : TImage;
    ...   : ..  // other records
  end;

var
  ShowLeft   : array[1..24] of TShow;
  ShowRight  : array[1..30] of Tshow;
  ...

{ main code }

procedure PositionPicture(Im : TImage);
var
 FirstRow = set of (imA1, imA2, imA3, imA4, imA5, image25, image26, image27, 
            image28, image29, image30);
 SecondRow = set of ( .. different ones ..);
 ..
 FifthRow = set of ( ... );
 T0 : integer; // should contain the image.top value for all first row images
 K,L : integer;
begin
  if Im in FirstRow then T0 := 40;   // THIS GOES WRONG !!!!  
                                     // 40 is for the first row
  K := im.Picture.Height;  // actual height of the picture now in Im
  L := 150 -K;  // all images have a default height of 150 pixels.
  Im.Top := Im.Top + L; // move down Im by L 
  Im.Height := K;   // Im.top is now no longer 40, so for a new picture we     
end;                // need to get the original position back

Procedure MainProgram;
begin
  ...
  PositionPicture(ShowLeft[3].image);  // e.g. 3 here
  ...
end;

Procedure TForm1.FormCreate(Sender: TObject);
begin
  ShowLeft[1].image := imA1;
  ..
  ShowLeft[24].image := imA24; 
  // ... etc
end;
image delphi set delphi-10.1-berlin
2个回答
0
投票

利用所有.align对象的TImage属性并将其设置为alBottom!通过这种方式,他们将自己对齐在一起,您无需自己计算每个属性的.Top属性值。

如果您需要在单独的图像之间留出一些间距,您可以根据需要设置.Margins.Bottom / .Top.AlignWithMargins := true;

也许您需要在“LeftPanel”和“RightPanel”中放置额外的TPanel才能使其看起来正确,但您对表单设计的描述有点模糊,所以这更像是对我的猜测......


0
投票

你的“一套”概念确实是不正确的。您正在考虑更多关于集合的数学定义,其中集合可以用于任何元素。在Delphi中集合具体涉及枚举类型定义,有点像这样

type
  TRow1Ref = (imA1, imA2, imA3, imA4, imA5, image25, image26, image27, 
        image28, image29, image30);

  FirstRow = set of TRow1Ref;

但这不是你想要实现的目标。这些不是图像。 imA1的内部值为0,imA2的值为1,依此类推。您定义的任何集合最终将在内部映射到字节或字等。

相反,你想使用某种数组或集合,例如

var
  FirstRow : TObjectList<TImage>;

(实现这一目标的方法有很多种。)

© www.soinside.com 2019 - 2024. All rights reserved.