PDA

View Full Version : TImage doesn't show



MarkyD
19-10-2003, 02:37 PM
I'm having trouble displaying a TImage component on a scrollbox. I'm attempting to create a TImage component on a scrollbox, initialize it, load in an image from a file, and finally display it on the scrollbox. I can happily display the image when loading it at design-time or runtime, but only on a TImage which was created at design-time, not runtime --- so I know that there isn't anything wrong with the image itself. I can't get a hint to appear either, so it suggests the control isn't being displayed at all.

This is the code I'm using:

var
Image: TImage;
{...}
//create the image and initialize it
Image:=TImage.Create(ScrollBox);
Image.Visible:=False;
Image.Stretch:=True;
Image.ShowHint:=True;
Image.Hint:='Bleh';
Image.Left:=0;
Image.Top:=0;
Image.Width:=100;
Image.Height:=100;
{...}
//load in an image from a file
Image.Picture.LoadFromFile('C:\Bleh.png');
{...}
//display the image on the scrollbox
Image.Visible:=True;

As far as I know, that should work. Any ideas as to what's wrong? It feels like I'm doing something unbelievably stupid here but I don't know what...

Cheers for any help. :)

tux
19-10-2003, 03:42 PM
try Image.parent := ScrollBox1

tux
19-10-2003, 03:44 PM
procedure TForm1.Button1Click(Sender: TObject);
var
i,
j: Integer;

Count: Integer;

Image: TImage;

GPI: TGPI;

begin
Count := 0;
for j:=1 to NumGPI div 10 do
for i:=1 to 5 do
if Count < NumGPI then
Begin
GPI &#58;= TGPI.Create;
GPI.LoadGPI&#40;&#123;GPI&#91;Count&#93;.FileName&#125;GPIPath + FileList&#91;Count&#93;&#41;;

Image &#58;= TImage.Create&#40;ScrollBox1&#41;;
with Image do
Begin
Parent &#58;= ScrollBox1;

Left &#58;= &#40;8 + &#40;i *&#40;128 + 16&#41;&#41;&#41; - &#40;128+16+4&#41;;
Top &#58;= &#40;8 + &#40;j *&#40;128 + 16&#41;&#41;&#41; - &#40;128+16+4&#41;;

Width &#58;= 128;
Height &#58;= 128;

Stretch &#58;= True;

Tag &#58;= Count;

Visible &#58;= True;

Picture.Bitmap &#58;= GPI.TGA;
end;
GPI.Free;

Inc&#40;Count&#41;;
end;
end;


give that a go

MarkyD
19-10-2003, 03:53 PM
Heh, so simple...cheers it works! :)

tux
19-10-2003, 04:07 PM
good good :)