-1

I have a VCL form with a left panel with 24 images (imA1 .. imA24) of TImage and a right panel with 30 images (image25 .. image53) of TImage. All images are 100 x 150. These images may load pictures of 100 width, but of different height. The plan is to adapt the Image.Height and Image.Top in such a way that all pictures shown will be aligned by the bottom of the Timage frame. As each image will be loading different pictures during run time, I need to store the Image.Top positions (I have 5 rows of pictures left and right). The idea was to let this be done by a separate procedure. See code example. The issue I am facing is that apparently my use of the 'set of' functionality is incorrect, or the use of the 'in' operator. Anybody any suggestions? Thanks - Fred (One alternative I found is to store the original top position in a separate record field for all images. Perhaps easier. But why does this use of 'set of' not work?)

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;
Fred
  • 23
  • 4
  • 1
    Take a look at [Structured Types](http://docwiki.embarcadero.com/RADStudio/XE7/en/Structured_Types) and scroll down to `Sets`. In general, you should at least once read [Delphi reference](http://docwiki.embarcadero.com/RADStudio/XE7/en/Delphi_Reference) – Tom Brunberg Apr 30 '19 at 13:57
  • Tom, I did consult (various) sources including the one you referenced. Apparently my interpretation of those texts was / is wrong. I felt that already and that is why I approached this forum. – Fred May 03 '19 at 13:52

2 Answers2

0

Your concept of 'set of' is indeed incorrect. You are thinking more in mathematical definitions of sets, where a set can be made up on anything for elements. In Delphi set of specifically relates to enum type definitions, a bit like this

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

  FirstRow = set of TRow1Ref;

But this is not what you are trying to achieve. These are not images. imA1 will be given an internal value of 0, imA2 a value of 1 and so on., and any set you define will ultimately map to a byte or word etc. internally.

Instead you want to use some sort of array or collection, e.g.

var
  FirstRow : TObjectList<TImage>;

(There are many alternative ways of achieving this.)

Dsm
  • 5,870
  • 20
  • 24
0

Make use of the .align property of all the TImage objects and set it to alBottom! This way they align themself on top of each other and you don't have to calculate the value of the .Top property for each one by yourself.

If you need some spacing between separate images you can set .Margins.Bottom / .Top to your needs and .AlignWithMargins := true;.

Maybe you need additional TPanels placed inside your "LeftPanel" and "RightPanel" to make this look properly, but your description of the form design is a litte bit vague, so this more of a guessing of mine...

Delphi Coder
  • 1,723
  • 1
  • 14
  • 25
  • Thanks, I tried align already, but that made all images move to the bottom and they stack on top of each other (in order of creation). A lot of panels will be needed to overcome this problem. It can be solved, but with more coding. I hoped for an 'elegant' solution I was not aware of. At least I now know that the 'set' option is not feasible. – Fred May 03 '19 at 14:29