Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1180
  • Last Modified:

TImage form ImageList

Who can i show an image from an imagelist ?
is there a component for it ?
I don't want to load it manually, because i change the icon in the ImageList and want that it is automatically updated in every TreeView, ListView, ... and in my TImage !
0
snoopy_Spy
Asked:
snoopy_Spy
  • 5
  • 4
1 Solution
 
LischkeCommented:
Hi Snoopy,

do it so: assign an event handler to TImageList.OnChange. In this handler you can retrieve the imagelist bitmap:

  FMyImage.Picture.Bitmap.Handle := FMyImagList.GetImageBitmap;

Ciao, Mike
0
 
snoopy_SpyAuthor Commented:
But where can i select the index ?
0
 
snoopy_SpyAuthor Commented:
and how can i recognize which image was changed ?
The TImage should only be reainted, when the image with the index was changed !
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
EpsylonCommented:
I don't think you can detect which image in the list has been changed...

Use this to get an image with a specific index:

procedure TForm1.Button1Click(Sender: TObject);
var b: TBitmap;
begin
  b := TBitmap.Create;
  ImageList1.GetBitmap(index, b);
  Image1.Picture.Assign(b);
  b.Free;
end;
0
 
EpsylonCommented:
This is even better:

procedure TForm1.Button1Click(Sender: TObject);
begin
  ImageList1.GetBitmap(index, Image1.Picture.Bitmap);
end;
0
 
snoopy_SpyAuthor Commented:
Epsylon,
Are you sure, that the 2nd one is correct ?
I get an EAccessViolation Exception when i close the application !
Can i make it with an Handle ?
I don't want to create every time a TBitmap  
0
 
EpsylonCommented:
I have no problems with it, so I guess it must be something else that causes the exception. I've tested this in Delphi 3 and 5.
0
 
snoopy_SpyAuthor Commented:
I found it, why i get the exception ! (I use D5)
This now gets no exception
    if i <> nil then
        i.GetBitmap(0, im.Picture.Bitmap);

But only the first time the OnChange Event is called, the Bitmap is loaded. The other calls doesn't change the Bitmap !

when i use :

    if i <> nil then
    begin
        im.Picture.Bitmap := nil;
        i.GetBitmap(0, im.Picture.Bitmap);
    end;

it works, but the image is "flashing ?" - I change the Image every 250 ms and it's blinking ....
0
 
EpsylonCommented:
Set form1.doublebuffered to true or put the TImage inside a panel and set panel.doublebuffered to true. Using a panel increases speed and consumes less memory.
0
 
snoopy_SpyAuthor Commented:
Thanxs
Now working fine !
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now