From: gwhit41980@aol.com (GWhit41980) Subject: Re: Can't create TImage at runtime Date: 13 Mar 1999 00:00:00 GMT Message-ID: <19990313071453.12661.00000161@ngol03.aol.com> References: <36EA405D.333F1629@iol.ie> X-Admin: news@aol.com Organization: AOL, http://www.aol.co.uk Newsgroups: comp.lang.pascal.delphi.misc In article <36EA405D.333F1629@iol.ie>, Simon Figg writes: >Hi, > Can anyone explain why, when I run the following code, I see nothing >in 'Image', while 'Image1' (created at design time) works perfectly? > > >procedure TForm1.Button1Click(Sender: TObject); > >var Image: TImage; > >begin > Image := TImage.Create(Form1); > Image.Top := 10; > Image.Left := 10; > Image.Width := 100; > Image.Height := 100; > Image.Picture.LoadFromFile('d:\bitmaps\a.bmp'); > Image1.Picture.LoadFromFile('d:\bitmaps\a.bmp'); >end; > > >Cheers, >Simon > This has to be the commonest mistake of all. Without a parent it won't show. Image.Parent:= Form1; it's also more usual to do Image:= TImage.Create(self); Self being the current Owner. In this case but whatever it's on top of in general. Setting the parent tells the Image where it is Top, Left etc are relative to the parent. ie if you Set the parent to a TPanel, Top and Left of 0,0 will be the Top Left of the panel. And the Image will show on the panel. hth Gordon. http://members.aol.com/gwhit41980/ MGCSoft