Home General

RB 21.03, custom preview and toolbar button images

Hi,
we recently upgrader Report Builder from 20.04 to 21.03. While testing some code I found out a weird bug. We use custom preview for quite some years now built as per rbWiki suggestions. On this custom preview which is part of our major project we added a button to prepare a special form of email and the button has dedicated image not changed since the creation of the preview form. The bitmap is stored in a dedicated resource file. The problem is that from RB 21.03 the image is something different, something that is "stock" from RB.

In unit named TppAdxPreview we have the following code that served well for years:
procedure TppAdxPreview.CreateToolbarItems;
var
  idx1, idx2 : Integer;
  cMaskColor : TColor;
  bmp : TBitmap;
  Stream: TResourceStream;
begin
  inherited;
  //Save position of Email button
  idx1 := Toolbar.Items.IndexOf(EmailButton);
  Toolbar.BeginUpdate;
  try
    FCodedEmailButton := Toolbar.AddButton();
    //FCodedEmailButton.ImageIndex := ToolImageList.AddTool('PPCODEDEMAIL');
    //instead of line above, here is the code that does "the same" and works:
    bmp := TBitmap.Create;
    try
      Stream := TResourceStream.Create(hInstance, 'PPCODEDEMAIL', RT_RCDATA);
      try
        bmp.LoadFromStream(Stream);
        cMaskColor := Bmp.Canvas.Pixels[0, Bmp.Height-1];
        FCodedEmailButton.ImageIndex := ToolImageList.AddMasked(Bmp, cMaskColor);
      finally
         Stream.Free;
      end;
    finally
      bmp.Free;
    end;
    //till here...
    FCodedEmailButton.OnClick := ehToolbutton_Click;
    FCodedEmailButton.Tag := 100;
    FCodedEmailButton.Hint := 'Pošlji kodiran e-mail';
  finally
    Toolbar.EndUpdate;
  end;
  //Move newly created button adjacent to the original email button
  idx2 := Toolbar.Items.IndexOf(FCodedEmailButton);
  Toolbar.Items.Move(idx2, idx1+1);
end;
How can I get the correct bitmap back?

Best regards,
Goran
Goran Brumen
Audax d.o.o.

Comments

  • Hi Goran,

    Call AddTool('CodedEmail', Bmp) or AddToolWithMask('CodedEmail', Bmp, Msk). I think the first version will work for you.

    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • Hi Nard,
    I tried many variants and yes, the first one is close to what I need but the transparency does. It is relatively okay with silver skin since what should be transparent is in silver but is visible.

    The second call is better but that means I have to prepare the mask BMP. If I use the second variant, I guess the BMP should be in 256 shades of gray? Black is transparent, white is opaque?

    Best regards,
    Goran
    Goran Brumen
    Audax d.o.o.
  • edited May 2022
    Hi Nard,

    don't bother, I solved the problem. The mask bitmap did not work, at least not as black&white image. So I convereted the bitmap image to transparent PNG and now I use slightly different code. Maybe it will help somebody.
    procedure TppAdxPreview.CreateToolbarItems;
    var
      idx1, idx2 : Integer;
      BMP: TBitmap;
      PNG: TPNGObject;
      StrPng : TResourceStream;
    begin
      //Check the same procedure in ppPreview.pas
      //Adding dedicated button for sending coded emails
      inherited;
      //Saving the position of stock e-mail button
      idx1 := Toolbar.Items.IndexOf(EmailButton);
      Toolbar.BeginUpdate;
      try
        FCodedEmailButton := Toolbar.AddButton();
        //Load PNG from resource (resppAxPreview) and convert to transparent TBitmap
        PNG := TPNGObject.Create;
        BMP := TBitmap.Create;
        try
          StrPng := TResourceStream.Create(hInstance, 'PPCODEDEMAILPNG', RT_RCDATA);
          try
            //Load PNG
            PNG.LoadFromStream(StrPng);
            //Setting the transparency for this particular image
            BMP.Transparent      := True;
            BMP.TransparentColor := clBlack;
            //Convert data into BMP
            BMP.Assign(PNG);
            //Assign BMP to Image list of tools (buttons)
            FCodedEmailButton.ImageIndex := ToolImageList.AddTool('CodedEmail', BMP);
          finally
            StrPng.Free;
          end;
        finally
          PNG.Free;
          BMP.Free;
        end
      finally
        Toolbar.EndUpdate;
      end;
      //Move new button just right of stock email button
      idx2 := Toolbar.Items.IndexOf(FCodedEmailButton);
      Toolbar.Items.Move(idx2, idx1+1);
    end;
    I hope somebody find this useful.

    Best regards,
    Goran
    Goran Brumen
    Audax d.o.o.
Sign In or Register to comment.