Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing garbage DFM data from TImage32 (Graphics32 library)

I have a control derived from TImage32:

TChromaDisplay = class(TImage32)

Everything is fine except that when I drop my TChromaDisplay on the form, the resulted DFM file is huge (300KB instead of <1KB) because I have garbage data (it is just a gray image) saved in the Bitmap.Data field. The Bitmap image is created and filled with gray color every time I drop my control on a form. I don't want to save the content of the image (garbage) to the DFM file since it makes the EXE larger but I don't know how.

Probably I need to write somewhere in TChromaDisplay.Create that I don't have any image data saved/stored in my TChromaDisplay. But I don't know where/how to do it.

  object Display: TChromaDisplay
    Left = 0
    Top = 0
    Width = 1465
    Height = 246
    Bitmap.Data = {
      C0000000C0000000EBEBEBFFEBEBEBFFEBEBEBFFEBEBEBFFEBEBEBFFEBEBEBFF
      EBEBEBFFEBEBEBFFEBEBEBFFEBEBEBFFEBEBEBFFEBEBEBFFEBEBEBFFEBEBEBFF
      EBEBEBFFEBEBEBFFEBEBEBFFEBEBEBFFEBEBEBFFEBEBEBFFEBEBEBFFEBEBEBFF
      etc
      etc
      etc

I have tried this in Create but won't help:

Bitmap.Width := 1;
Bitmap.Height:= 1;
like image 439
Server Overflow Avatar asked Jun 10 '12 12:06

Server Overflow


1 Answers

Update:

Looking at design time image dialog GR32_Dsgn_Bitmap.pas for TImage32.Bitmap property, the Clear button there uses the Bitmap.Delete procedure what just sets the bitmap size to 0x0. So you can try to call it to clear the bitmap before the form stream is saved:

type
  TChromaDisplay = class(TImage32)
  protected
    procedure WriteState(Writer: TWriter); override;
  end;

implementation

procedure TChromaDisplay.WriteState(Writer: TWriter);
begin
  Bitmap.Delete;
  inherited;
end;

But it still doesn't explain why you have a bitmap data when you put a control on the form. You can also call the Bitmap.Delete in your control constructor after inherited part is done (when the Bitmap is already instantiated).

Still untested, since I can't simulate your problem.

like image 113
TLama Avatar answered Oct 19 '22 01:10

TLama