?
Solved

How to set an image on a form at runtime

Posted on 2003-03-31
4
Medium Priority
?
187 Views
Last Modified: 2010-04-06
I have been looking at setting a picture at runtime on a delphi form. Having the components TImage and TImage list I feel it should be easy. i.e load the pictures into the image list and then set TImage to one of the stored images. I must be missing something because I do not see how to link the components to do this. Can anyone help?
0
Comment
Question by:scifibrian
  • 2
4 Comments
 
LVL 4

Expert Comment

by:cjm30305
ID: 8242190
You must do the following...  I have tried to do this in the past as well, and this is what i had to do.

Image1: TImage;
Image2: TImage;
Image3: TImage;
Image4: TImage;
Image5: TImage;

Durring design make image 1 - 4 visible := False and assign the desired image to each, instead of having in a TImageList.

Then depending on the status or whatever you can set Image5 to whatever image you want such as

procedure UpdateStatus(Status: string);
begin
 if Status = 'Image1' then
   Image5.Picture := Image1.Picture
 else
 if Status = 'Image2' then
   Image5.Picture := Image2.Picture
 .....
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  UpdateStatus('Image1');
end;

This will get you the desired effect that you are looking for.

Cheers.

0
 
LVL 4

Accepted Solution

by:
cjm30305 earned 420 total points
ID: 8242293
I am so sorry dude.  I was not thinking.....  DISREGARD ALL THAT I SAID BEFORE.  This is all that you need.  I was thinking back to an old program that I wrote a long time ago, and it has been a long day.


ImageList1.GetBitmap(0, Image1.Picture.Bitmap);


0 is the index of the image within the list, and then you pass it the parameter on where to view the image.

Cheers.
0
 
LVL 35

Expert Comment

by:Slick812
ID: 8242299
hello scifibrian, Why would you use a TImage? If you do not need the events or properties of a TImage you might could use a TBitmap and just draw it on the Form in the Form's OnPaint event.



  private
    { Private declarations }
    BkgBmp: TBitmap;


procedure TForm1.FormCreate(Sender: TObject);
begin
BkgBmp := TBitmap.Create;
BkgBmp.LoadFromFile('E:\BackBmp.bmp');
{OR load from resource}
//BkgBmp.LoadFromResourceName(hInstance,'BACKGND');
end;


procedure TForm1.FormPaint(Sender: TObject);
begin
//Canvas.Draw(0,0,BkgBmp);
Canvas.StretchDraw(ClientRect, BkgBmp);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
FreeAndNil(BkgBmp);
end;


- - - - - - - - - - - - - - - - - - - - - - -
If you are loading a single Image from Disk, I do not see a need for a TImageList, if you have many Images, then an ImageList might be helpful.
Ask questions if you need more info.
0
 

Author Comment

by:scifibrian
ID: 8242471
Thanx, that was just the syntax I was looking for.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Integration Management Part 2
SQL Database Recovery Software repairs the MDF & NDF Files, corrupted due to hardware related issues or software related errors. Provides preview of recovered database objects and allows saving in either MSSQL, CSV, HTML or XLS format. Ensures recov…
Suggested Courses
Course of the Month8 days, 21 hours left to enroll

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question