?
Solved

How to set an image on a form at runtime

Posted on 2003-03-31
4
Medium Priority
?
184 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 34

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month10 days, 16 hours left to enroll

770 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