How reduce amount of stored bitmaps

Hi,

 I've a form with dozens of one same component... made by myself in the early D1 period. Now it's time to alter it...

Ok, what it does : It's a sort of range visualizer. You give two values one limit for above, one for below.

If a given data-value (db or not db) is in the selected range, then a certain bitmap is shown, if not, another bitmap is shown. Now, every single component stored these bitmaps himself! Not so good, but heck it worked then.

Now, I want to do the following :

 - put an image container on the form (like image list, or PicClip of RxLib) I prefer to use PicClip, because ImageList seems to have some resource leaks.
 - put a component on the form and let this one point to a certain Image container (selectable in design-time)

 --> this way I avoid storing multible same bitmaps.

 --> But how can you do this? How can I let one component refer to another one, so that I can share one component with several others..., without storing this shared component in every component which uses it!

Is this the only way, but then I still create a TPicClip for every component and that's just what I don't want!! :

 unit ShowRange;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  PicClip;

type
  TShowRange = class(TCustomControl)
  private
    { Private declarations }
    fPicClip : TPicCLip;
    procedure SetPicClip(vPicClip : TPicClip);
  protected
    { Protected declarations }
  public
    { Public declarations }
  published
    { Published declarations }
   property PicClip: TPicClip read fPicClip write SetPicClip;
  end;

procedure Register;

implementation

procedure TShowRange.SetPicClip(vPicClip: TPicClip);
begin
 if vPicClip <> fPicClip then begin
  fPicClip.Assign(vPicClip);
 end;
end;

procedure Register;
begin
  RegisterComponents('MyComponents', [TShowRange]);
end;

end.

 
Example please!

Regards, Zif.


LVL 8
ZifNabAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chrismoCommented:
You're almost there. Just remove the .Assign call in the Set accessor method. Replace it with:

fPicClip := vPicClip

Now fPicClip is pointing to the assigned vPicClip - you won't be creating an additional TPicClip object, just pointing to the one that exists. Do this as often as you need.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MadshiCommented:
chrismo, you're right.

ZifNab, and don't forget to hook the TPicClip changes. I don't know TPicClip, so I can't tell you how you can do this. But if you don't hook the changes your little component will crash when you remove the picClip without deleting the reference in your component before.

Regards, Madshi.
0
ZifNabAuthor Commented:
Hi all,

Hmm, very simple, ... thanks.

thanks for the replies. Now, If I use ImageList for example... how should hook then work?

Regards, Zif.
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

MadshiCommented:
ZifNab,

look at the method "RegisterChanges" and the event "OnChange". In the event handler you should check if the imageList your component is referencing still exists and if the image index still exists. If not, your component should remove the reference to that imageList.
I've no sources, but I think the delphi help explains it good enough...

Regards, Madshi.
0
ellessarCommented:
An option which you have is to pass the index of a specific bitmap to your bitmap lister, and let that return a bitmap handle to you based on that index value. You could "store" all your images in a TList or something similar then. Once you have the bitmap handle you can do quite a lot with the image.... You said you did not want to have to copy anything accross, and this may be an alternative.
0
MadshiCommented:
ellessar,

each and every bitmap handle consumes windows system resources. Don't forget this. ImageList only consumes one handle per list.

Regards, Madshi.
0
ellessarCommented:
Just goes to show, we learn something new every day... I
never realised that the ImageList is actually exposing
a basic windows image list object. That might also
explain the apparent memory leaks they are experiencing.

The windows help listing says the following:

An image list is a collection of same-sized images,
each of which can be referred to by its index. Image
lists are used to efficiently manage large sets of
icons or bitmaps. All images in an image list are
contained in a single, wide bitmap in screen device
format. An image list may also include a monochrome
bitmap that contains masks used to draw images
transparently (icon style).


0
MadshiCommented:
ellessar,

have you ever experienced memory leaks with ImageLists? I'm working with them and never noticed something like that. Perhaps I just didn't look close enough...

Regards, Madshi.
0
ZifNabAuthor Commented:
Madshi,

 Well, I don't know anymore if TImageList has a resource leak, I thought I read about it somewhere, but I can't find it anymore. A good link to find about bugs is here http://www.dataweb.nl/~r.p.sterkenburg/bugsall.htm

regards, Zif.
0
ZifNabAuthor Commented:
mmmm, is it possible to get something like this?

A user can refer to a TPicClip OR to a TImageList?

Regards, Zif.

0
ZifNabAuthor Commented:
Thanks all.
0
MadshiCommented:
Hey ZifNab,

I thought you was on vacation already?
0
ZifNabAuthor Commented:
I'm going ! In about 2 hours :-) Regards, Zif.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Fonts Typography

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.