Frage

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;
War es hilfreich?

Lösung

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.

Andere Tipps

This is not "garbage". It's an image (whether it's one you assigned or one that the control creates in it's constructor). It's a bitmap located at position 0, 0 with a width and height of 1465, 246.

The BitmapData is the data in the bitmap (the pixels, etc.), encoded as a hex string so it will go in the text dfm.

The solution is to figure out how the bitmap is being assigned. It's either:

  • In the component's constructor (a default image?)
  • On your form (you've assigned an image in the IDE)
  • It's not being removed from the DFM from a previous time it was assigned.

The first one requires that you closely examine the source code of the component to figure out where it's being assigned. You can check to see what the bitmap property is called internally (for instance, FBitmap or FImage), and then search for places it gets an image assigned (LoadFromFile, LoadFromStream, LoadFromResource, Assign, and so forth).

The second and third: Backup your dfm just in case. Delete the component from your form. Comment out any code related to it, so your unit will compile. Right-click it, and choose View as Text. Search for TChromaDisplay (or just TChroma), and delete everything you find in the dfm related to it. Right-click and chhose View as Form, and then build your project. Go back into the dfm and make sure all traces of TChroma are still gone.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top