Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

Custom print preview and new button

Hi,

I have a small problem regarding extra button on custom print preview. Following advices on rbWiki and many posts about it here I succesfully created print preview with additional button which is used for creating PDF of the report previewed and then the file is sent to uniform dialog box for sending coded e-mails. Since I have 2 buttons for sending e-mails on the print preview, I want that added button has new image (glyph), which is similar to existing.

I overrided CreateToolBarItems procedure as follows:
procedure TppAdxPreview.CreateToolbarItems;
var
  idx1, idx2 : Integer;
begin
  inherited;

  idx1 := Toolbar.Items.IndexOf(EmailButton);
  Toolbar.BeginUpdate;
  FCodedEmailButton := Toolbar.AddButton();
  FCodedEmailButton.ImageIndex := ToolImageList.AddTool('PPCODEDEMAIL');
  FCodedEmailButton.OnClick := ehToolbutton_Click;
  FCodedEmailButton.Tag := 100;
  FCodedEmailButton.Hint := 'Send coded e-mail';

  Toolbar.EndUpdate;
  idx2 := Toolbar.Items.IndexOf(FCodedEmailButton);
  Toolbar.Items.Move(idx2, idx1);
end;
Newly created bitmap ppCodedEmail.bmp is stored in resource under the code PPCODEDEMAIL. I have added the resource under whole project and leter moved it in special and to the preview dedicated resource list. Unfortunatelly the button shows image under code PPNOIMAGE. If I use some code used for other buttons in RB it normally shows. I rebuilded the resource numerous times, also the project but no success. What am I missing? I am using RB 18.01.

Thank You very much in advance and best regards,
Goran


Goran Brumen
Audax d.o.o.

Comments

  • edited July 2018
    Hi Goran,

    The TppToolImageList simply utilizes the Windows API to access resource files. See the ppBitmapFromResource routine in the ppUtils.pas file for how this is done in ReportBuilder.

    It appears that the Windows API cannot find your resource. This could be caused by it being loaded incorrectly or an invalid file format. I suggest creating a simple Delphi application to test loading the resource image to a TImage or other Delphi component before attempting with ReportBuilder.

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • Hi Nico,

    I have looked at that routine, yes and I was wondering as well why the resource can't be found. Maybe due to the Windows 10 (build 1709), don't know. I finally modified the routine as below and it works. The only thing I am uncertain is if the index assigned is correct.
    procedure TppAdxPreview.CreateToolbarItems;
    var
    idx1, idx2 : Integer;
    cMaskColor : TColor;
    bmp : TBitmap;
    Stream: TResourceStream;
    begin
    inherited;

    idx1 := Toolbar.Items.IndexOf(EmailButton);
    Toolbar.BeginUpdate;
    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 := 'Send coded e-mail';

    Toolbar.EndUpdate;
    idx2 := Toolbar.Items.IndexOf(FCodedEmailButton);
    Toolbar.Items.Move(idx2, idx1);
    end;
    And the resource file attached to this unit is very simple:
    PPCODEDEMAIL RCDATA ppCodedEmail.bmp
    Best regards,
    Goran
    Goran Brumen
    Audax d.o.o.
Sign In or Register to comment.