Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I implement an efficient ressource management ?

Status
Not open for further replies.

David28

Programmer
Nov 14, 2004
8
DE
Hello,

In order to make special effects on bitmaps (bluebox, changing the brightness etc.)
I programmed an abstract class which I called TFilter.

TFilter has follwing main attributes:

SourceBitmap //The bitmap which should be modified.
Bitmap //The target bitmap. This attribute contains the result.
//The constructor creates an instance of FBitmap (which belongs to this
//attribute) so the user may set the SourceBitmap attribute only.

Height
Width //If these attributes are 0 ( the default)
//the whole SourceBitmap will be modified.
// Otherwise it defines a section.
// If one of these attributes exceeds
// SourceBitmap's width or height it's set
// to the possible maximum.

Execute // This is an abstract method which starts
// the appropriate effect.

ResetFilter // This method sets all attributes to the default values
// and creates an instance of FBitmap.


Following example shows how to use it.


var
CopyFilter : TCopyBitmapFilter;
// The TCopyBitmapFilter class copies a Bitmap.
// It has TFilter as base class.

begin
CopyFilter.SourceBitmap := Image1.Picture.Bitmap;
CopyFilter.Execute;
Image2.Picture.Bitmap := CopyFilter.Bitmap;
Image2.Refresh;
end;

If I use this example the first time all works fine.
But if I use it a second time I get an E/A AccesViolation:



//-----------------------------------------------------------------------
//SetSourceBitmap:
// This procedure varies from standard property handling.
// If Bitmap's Heigth or Width is lower than SourceBitmap's
// Bitmap's Height or Width will be exceed to SourceBitmaps.
//-----------------------------------------------------------------------
procedure TFilter.SetSourceBitmap(SourceBitmap:TBitmap);
begin
if FBitmap.Width < SourceBitmap.Width then //Here happens the exception !!!
//It's in -FBitmap.Width.
begin
FBitmap.Width := SourceBitmap.Width;
end;

if FBitmap.Height < SourceBitmap.Height then
begin
FBitmap.Height := SourceBitmap.Height;
end;


FSourceBitmap := SourceBitmap;


end;




The problem can be solved easily:
begin
CopyFilter.ResetFilter;//!!!!!!
CopyFilter.SourceBitmap := Image1.Picture.Bitmap;
CopyFilter.Execute;
Image2.Picture.Bitmap := CopyFilter.Bitmap;
Image2.Refresh;
end;

So it seems that every time I want to use the filter,
I have to create a new instance of FBitmap.

And now (at last) my quuestions :

What happens with the old instance ?
Can this litter my main memory ?

How can I implement an efficient ressource management ?
Any tips,guidlines, advices ?

How can I plan it in a professionell way ?

What is if several objects points on the same instance ?
Get I problems when I free such an instance ?

Thank you all very much for your answers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top