-5

I'm using Delphi and I created an array of ten elements of type TImage whit this name and structure:

Form3.images[1..max] of TImage. 

I tried to initialize it in this way:

for x := 1 to max do
begin
  images[x] := TImage.Create(Form3);
  images[x].AutoSize := True;
  images[x].Name := 'image' + IntToStr(x);
  images[x].Visible := true;
  images[x].Parent := Form3;
end;

After that I tried to put the content of another variable (called Form3.a1:TImage) to every element of the array.

I tried to do this with these instructions:

for i := 1 to max do
begin
  Form3.Images[i]:=Form3.a1;             // ( Form3.a1: TImage) <- this is visible
end;

(I don't know if using the instructions before, is the right thing to do) After that I changed positions of array's images:

//Form3.square:TShape

x := Form3.square.Left;
y := Form3.square.Top;
Form3.Images[1].Top := y + 70;
Form3.Images[1].Left := x + 60;
...
Form3.Images[1].Top := y + 10;
Form3.Images[1].Left := x + 50;

I set different positions for each image of the array but when I run the program, images of the array aren't visible. I also tried to set Form3.square.visible=false but nothing changes.

This is what I want:

  • have the same contents between variable a1 and variables of the array images, changing only positions
  • make array's images visible (I tried images[x].Visible := true; but it doesn't work).

please i need help, I can give other details. Thank you.

Black8AC
  • 1
  • 3

2 Answers2

3

You forget to set the control's position; Left and Top. This is preferrably done by calling SetBounds. Also the dimensions are not specified , but that is taken care of by the AutoSize property (it wouldn't need it for becoming visible though).

NGLN
  • 43,011
  • 8
  • 105
  • 200
  • Oh thank you! And sorry because I Forgot to say that I Set positions! Positions of images are the same of another object (that's a shape). I tried to put shape.visible=false to see if images were under it, but I couldn't see the images... pls heeeeeelp :( – Black8AC May 07 '12 at 16:51
1

Provided you have set the position of the images in the images array (as you state in the comment on te other answer), then the first code should work normally.

Check the following though:

  • Are the Width and Height properties of the ImageList Form3.Lista set? Note that when you change them, the ImageList is cleared.
  • Ensure that you are looking at the same TForm3 instance as where the Form3 variable points to. (You should not use that global form variable anyway!)

Now, about the second piece of code wherein you copy images from one to another:

  • Is a1 a (local) declared variable as you wrote halfway the question? Then Form3.a1 (which is a private field of TForm3) and a1 (the variable) are not the same!
  • Note that you are copying from Form3.a1 to Images[i]. Shouldn't that maybe the other way around?
  • If this indeed is what you want: Is Form3.a1 by any chance empty?

There are 2 more possibilities I can think of, but both would result in an exception, so I imagine these are not the case:

  • ImageList Form3.Lista holds no or not enough images,
  • Image Form3.a1 holds no bitmap, but a gif, jpeg or other graphic type.
Community
  • 1
  • 1
NGLN
  • 43,011
  • 8
  • 105
  • 200
  • but there are some problems: I didn't use an ImageList; The variable is only one and it's Form3.a1 . It has got a picture inside (a bitmap as I said). But, must I create an ImageList if I already have an images' array? – Black8AC May 07 '12 at 18:15
  • 1
    I assumed `Form3.Lista` is a `TImageList`, because you invoke `GetBitmap` on it. What type is `Form3.Lista` then? – NGLN May 07 '12 at 18:53
  • It is a TimageList that I created, but I didn't do anything on it. Only that thing that you read. Couldn't we solve the problem without using a list? Is it necessary if I have an array of images? I don't think and I hope so. Because I don't know how to use an imageList – Black8AC May 07 '12 at 20:27