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

Adding button to Preview

edited September 2008 in General
Using D7 and RB10
I need to add a button and code to the preview tab in RBuilder. I allow end
users to use the disigner so it has to be available to them when they click
preview tab. The button will serve a function that will export the data to
csv in a certain style not automatically supported by RB.
My question: What is the best way to implement a new button and code on the
preview tab? Does this require creating my own preview screen and will it
work with the Designer?

Comments

  • edited September 2008
    Hi Bob,

    Adding a new button to the preview window can be done by creating a custom
    preview plugin. This will work with the designer.

    Take a look at the article below on creating a Preview Plugin and see the
    ppPreview.pas file for how the toolbar buttons are created for the current
    preview. Your plugin would simply need to override the CreateToolbarItems
    routine and add a new button similar to the way it is done in the TppPreview
    class.

    -----------------------------------------
    Article: Creating a Preview Plugin
    -----------------------------------------

    Q: I've followed the tutorials and registered a Preview Form replacement but
    that did not affect the TppDesigner's Preview workspace.


    A: Do not use the form replacement, but rather, there is a different
    architecture built into the preview form that is registered by default.



    You will need to register a TppPreview descendent. The class you register
    is used to create the preview controls inside the standard print preview
    form and the designer preview workspace.


    Here is an example of creating a simple custom preview that access the
    viewer its been assigned in order to change the page color. You can also do
    more advanced operations such as adding and removing buttons and change the
    behavior of the preview form. Access the inherited controls via. protected
    properties and override the virtual methods in order to customize behavior.

    Open ppPreview.pas and view the TppPreview class as a guide to create a
    custom preview descendent.


    unit MyPreviewPlugin;

    interface

    uses
    ppPreview;

    type
    TMyPreviewPlugin = class(TppPreview)
    public
    procedure BeforePreview; override;

    end;


    implementation

    uses
    Graphics;


    procedure TMyPreviewPlugin.BeforePreview;
    begin
    inherited BeforePreview;

    Viewer.PageColor := clRed;

    end;

    initialization
    TppPreviewPlugIn.Register(TMyPreviewPlugin);

    finalization
    TppPreviewPlugIn.UnRegister(TMyPreviewPlugin);

    end.

    --
    Regards,

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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited September 2008
    I was able to use your example and make the background red. However, I am
    not clear on how to add the button and event code for the extra button. Do
    you have another example where a button is actually being addeed?

    Thanks,
    Bob

  • edited September 2008
    Hi Bob,

    The article shows the basics of creating a preview plugin however instead of
    implementing the BeforePreview event you will need to override the
    CreateToolbarItems routine and add the button from there.

    I created a rbWiki article and example to show how this should be done.

    http://www.digital-metaphors.com/rbWiki/Output/Preview/How_To...Add_a_Button_to_the_Preview

    --
    Regards,

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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited September 2008
    That was very helpful and easy once I saw your code.
    Thanks,
    Bob

This discussion has been closed.