Solved

How reduce amount of stored bitmaps

Posted on 1998-09-01
13
277 Views
Last Modified: 2013-12-03
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.


0
Comment
Question by:ZifNab
  • 5
  • 5
  • 2
  • +1
13 Comments
 

Accepted Solution

by:
chrismo earned 50 total points
ID: 1338363
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
 
LVL 20

Expert Comment

by:Madshi
ID: 1338364
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
 
LVL 8

Author Comment

by:ZifNab
ID: 1338365
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
 
LVL 20

Expert Comment

by:Madshi
ID: 1338366
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
 

Expert Comment

by:ellessar
ID: 1338367
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
 
LVL 20

Expert Comment

by:Madshi
ID: 1338368
ellessar,

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

Regards, Madshi.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Expert Comment

by:ellessar
ID: 1338369
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
 
LVL 20

Expert Comment

by:Madshi
ID: 1338370
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
 
LVL 8

Author Comment

by:ZifNab
ID: 1338371
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
 
LVL 8

Author Comment

by:ZifNab
ID: 1338372
mmmm, is it possible to get something like this?

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

Regards, Zif.

0
 
LVL 8

Author Comment

by:ZifNab
ID: 1338373
Thanks all.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1338374
Hey ZifNab,

I thought you was on vacation already?
0
 
LVL 8

Author Comment

by:ZifNab
ID: 1338375
I'm going ! In about 2 hours :-) Regards, Zif.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now