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

Preview Customization breaks from 9 - 10

edited June 2007 in Component Writing

Comments

  • edited June 2007
    Sorry about that.. accidentally sent.

    I had inherited from the TppPreview object in version 9.06 to put a button
    on the top specifically for exporting easily to a PDF and one for printing
    (because our clients werent figuring out which was the print button).

    We recently upgraded to 10.06 Pro (since we are moving to D2007) and now the
    Preview is done totally differently. I have tried to adjust my code to deal
    with the changes, however I keep getting access violations, but they arent
    specific to a line number.

    I have posted my code (well most of it, if you need more let me know) below
    if anyone could give me a tip on how to get this to work.

    Thanks in advance,
    Trevor

    ******************************
    TsynPDFPreviewPlugin = class(TppPreview)
    private
    //FCustomButton : TcxButton;
    //FCustomPrint : TcxButton;
    FCustomButton : TppTBXItem;
    FCustomPrint : TppTBXItem;

    FAutoSearchButton: TppTBXItem;
    FCancelButton: TppTBXItem;
    FEmailButton: TppTBXItem;
    FFirstButton: TppTBXItem;
    FLastButton: TppTBXItem;
    FNextButton: TppTBXItem;
    FPageNoEdit: TppTBXEditItem;
    FPageWidthButton: TppTBXItem;
    FPercent100Button: TppTBXItem;
    FPrintButton: TppTBXItem;
    FPriorButton: TppTBXItem;
    FTextSearchButton: TppTBXItem;
    FWholePageButton: TppTBXItem;
    FZoomPercentageEdit: TppTBXEditItem;

    procedure CustomButtonClickEvent(Sender: TObject);
    //procedure ShiftControls;

    protected
    //procedure PageChangeEvent(Sender: TObject); override;

    public
    procedure CreateToolbarItems; override;
    //procedure BeforePreview; override;
    procedure KeyDown(var Key: Word; Shift: TShiftState); override;

    end;


    procedure TsynPDFPreviewPlugin.CreateToolbarItems;
    begin
    Toolbar.BeginUpdate;

    FPrintButton := Toolbar.AddButton();
    FPrintButton.ImageIndex := ToolImageList.AddTool('PPPRINT');
    FPrintButton.Tag := Ord(paPrint);
    FPrintButton.OnClick := ehToolbutton_Click;
    FPrintButton.Visible := False;

    FEmailButton := Toolbar.AddButton();
    FEmailButton.ImageIndex := ToolImageList.AddTool('PPEMAIL');
    FEmailButton.OnClick := ehToolbutton_Click;
    FEmailButton.Tag := Ord(paEmail);
    FEmailButton.Hint := ppLoadStr(1093);

    Toolbar.AddSpacer();
    // AddSeparator();
    Toolbar.AddSpacer();

    FAutoSearchButton := Toolbar.AddButton();
    FAutoSearchButton.ImageIndex := ToolImageList.AddTool('PPAUTOSEARCH'); //
    (TppAutoSearchIcon);
    FAutoSearchButton.OnClick := ehToolbutton_Click;
    FAutoSearchButton.Tag := Ord(paAutoSearch);

    FTextSearchButton := Toolbar.AddButton();
    FTextSearchButton.ImageIndex := ToolImageList.AddTool('PPTEXTSEARCH');
    FTextSearchButton.OnClick := ehToolbutton_Click;
    FTextSearchButton.Tag := Ord(paTextSearch);
    FTextSearchButton.GroupIndex := 2;
    FTextSearchButton.AutoCheck := True;
    FTextSearchButton.Hint := ppLoadStr(1054); {'Enable the Text Search
    Toolbar';}

    Toolbar.AddSpacer();
    // AddSeparator();
    Toolbar.AddSpacer();

    FWholePageButton := Toolbar.AddButton();
    FWholePageButton.ImageIndex := ToolImageList.AddTool('PPZOOMWHOLEPAGE');
    FWholePageButton.OnClick := ehToolbutton_Click;
    FWholePageButton.Tag := Ord(paWholePage);
    FWholePageButton.GroupIndex := 1;
    FWholePageButton.AutoCheck := True;
    FWholePageButton.Checked := True;

    FPageWidthButton := Toolbar.AddButton();
    FPageWidthButton.ImageIndex := ToolImageList.AddTool('PPZOOMPAGEWIDTH');
    FPageWidthButton.OnClick := ehToolbutton_Click;
    FPageWidthButton.Tag := Ord(paPageWidth);
    FPageWidthButton.GroupIndex := 1;
    FPageWidthButton.AutoCheck := True;

    FPercent100Button := Toolbar.AddButton();
    FPercent100Button.ImageIndex := ToolImageList.AddTool('PPZOOM100PERCENT');
    FPercent100Button.OnClick := ehToolbutton_Click;
    FPercent100Button.Tag := Ord(pa100Percent);
    FPercent100Button.GroupIndex := 1;
    FPercent100Button.AutoCheck := True;

    FZoomPercentageEdit := Toolbar.AddEdit();
    FZoomPercentageEdit.EditWidth := 37;
    FZoomPercentageEdit.ExtendedAccept := True;
    FZoomPercentageEdit.OnAcceptText := ehZoomEdit_AcceptText;

    Toolbar.AddSpacer();
    // AddSeparator();
    Toolbar.AddSpacer();

    FFirstButton := Toolbar.AddButton();
    FFirstButton.ImageIndex := ToolImageList.AddTool('PPFIRSTPAGE');
    FFirstButton.OnClick := ehToolbutton_Click;
    FFirstButton.Tag := Ord(paFirst);

    FPriorButton := Toolbar.AddButton();
    FPriorButton.ImageIndex := ToolImageList.AddTool('PPPRIORPAGE');
    FPriorButton.OnClick := ehToolbutton_Click;
    FPriorButton.Tag := Ord(paPrior);

    FPageNoEdit := Toolbar.AddEdit();
    FPageNoEdit.EditWidth := 37;
    FPageNoEdit.ExtendedAccept := True;
    FPageNoEdit.OnAcceptText := ehPageNoEdit_AcceptText;

    FNextButton := Toolbar.AddButton();
    FNextButton.ImageIndex := ToolImageList.AddTool('PPNEXTPAGE');
    FNextButton.OnClick := ehToolbutton_Click;
    FNextButton.Tag := Ord(paNext);

    FLastButton := Toolbar.AddButton();
    FLastButton.ImageIndex := ToolImageList.AddTool('PPLASTPAGE');
    FLastButton.OnClick := ehToolbutton_Click;
    FLastButton.Tag := Ord(paLast);

    Toolbar.AddSpacer();
    Toolbar.AddSpacer();

    FCustomButton := Toolbar.AddButton();
    FCustomButton.Caption := '&Save to PDF';
    FCustomButton.Hint := 'Save to PDF';
    FCustomButton.OnClick := CustomButtonClickEvent;

    FCustomPrint := Toolbar.AddButton();
    FCustomPrint.Caption := '&Print';
    FCustomPrint.Hint := 'Print';
    FCustomPrint.Tag := Ord(paPrint);
    FCustomPrint.OnClick := ehToolbutton_Click;

    FCancelButton := Toolbar.AddButton();
    FCancelButton.Caption := ppLoadStr(ppMsgCancel);
    FCancelButton.OnClick := ehToolbutton_Click;
    FCancelButton.Tag := Ord(paCancel);
    FCancelButton.Enabled := False;

    Toolbar.EndUpdate;

    //This is how I was doing it before and is now commented out
    (*inherited CreateToolbarItems;

    ToolBar.ShowHint := True;

    FCustomButton := TcxButton.Create(Toolbar);
    FCustomButton.Caption := '&Save to PDF';
    FCustomButton.Parent := ToolBar;
    FCustomButton.Left := CancelButton.Left;
    FCustomButton.Top := CancelButton.Top;
    FCustomButton.Width := 85;
    FCustomButton.ParentShowHint := True;
    FCustomButton.Hint := 'Save to PDF';
    FCustomButton.LookAndFeel.Kind := lfStandard;
    FCustomButton.LookAndFeel.NativeStyle := True;
    FCustomButton.OnClick := CustomButtonClickEvent;

    FCustomPrint := TcxButton.Create(Toolbar);
    FCustomPrint.Caption := '&Print';
    FCustomPrint.Parent := ToolBar;
    FCustomPrint.Left := FCustomButton.Left + FCustomButton.Width + 7;
    FCustomPrint.Top := CancelButton.Top;
    FCustomPrint.Width := 85;
    FCustomPrint.ParentShowHint := True;
    FCustomPrint.Hint := 'Print';
    FCustomPrint.LookAndFeel.Kind := lfStandard;
    FCustomPrint.LookAndFeel.NativeStyle := True;
    FCustomPrint.OnClick := PrintButton.OnClick;

    CancelButton.Left := FCustomPrint.Left + FCustomPrint.Width + 7;
    PrintButton.Visible := False;
    ToolBar.Width := ToolBar.Width + FCustomPrint.Width +
    FCustomButton.Width + 14; *)
    end;
  • edited June 2007
    Hi Trevor,

    Yes the toolbars and menus have changed drastically since RB 9. I would
    suggest first copying the entire CreateToolbarItems routine from the
    TppPreview class to your overridden version inside your custom previewer and
    then running to be sure that works. Then begin adding your own buttons in
    one by one to see where the problem is happening. We have many customers
    who have successfully migrated their custom previews over to use the new
    toolbars and there is a bit more to it but we feel it is well worth it to
    get the higher quality look, feel, and functionality.

    --
    Regards,

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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited June 2007
    Hi,
    Thanks for your quick response. I have tried doing as you suggested,
    unfortunately, the buttons and the toolbar are not exposed to decendant
    classes, except through read-only properties, so I am forced to redeclare
    the objects. I only say this because I think it might be part of the
    problem. When I try to run a report and view the preview, I get access
    violations. I have stepped through my overloaded version and the errors are
    not comming directly from there. Any ideas?

    The code is basically the same as in the orgiinal message but without
    creating my custom buttons.

    I am thinking that maybe I should just inherit from TppCustomPreview and
    copy the functionality rather than inheriting directly from TppPreview.

    Thanks in advance,
    Trevor


  • edited June 2007
    I guess my theory is that the base class is trying to modify the properties
    of the buttons (i.e. enabling and disabling them) and since I had to
    reintroduce the buttons so that I could modify them, they base class is
    using its version of the buttons instead of my reintroduced ones and, since
    they are not created, I am getting AVs. However I cannot see a way around
    this because in the derived class I have no access to modify the buttons'
    properties.

    Would this be a correct assumption?

    Thanks in advance,
    Trevor


  • edited June 2007
    Hi Trevor,

    With the new architecture, it is very simple to add a button to the front or
    back of the Preview Toolbar. If however you need to insert a button inside
    the current buttons, you will need to override the CreateToolbarItems
    routine without calling Inherited and completely recreate each button that
    is present including the event handlers if necessary. You should still be
    able to use a descendent to the TppPreview class because all the buttons are
    declaired as public properties and the event handlers are protected so you
    should have access to everything you need.

    --
    Regards,

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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited June 2007
    That is what I figured. However, the buttons are exposed only as read only
    properties and so I cannot change their properties (like visible) or access
    them to create them.

    Is there a newer update that exposes them as read and write properties?


  • edited June 2007

    When a read-only property is an Object, you can access the Object and modify
    it's properties. What you cannot do is assign a new Object instance to
    replace the existing one.

    So in the case of the preview toolbar, you can modify the existing items,
    hide the existing items, and add new items. If that is not enough, then as
    Nico suggested you can override the CreateToolbarItems method and omit the
    call to inherited.


    --
    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com

    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited June 2007


    Ah, the subtle difference that was annoying me.


    Sorry if it seems that I am going over things a few too many times, but when
    I try to do this, it wont let me create the buttons at all; the IDE wont let
    it. So if I dont call inherited then the buttons are never created and I
    get AV's when the TppPreview class tries to set the enabled status for them.
    I tried redeclaring them, but that, of course, doesnt work.

    As it is I just created my custom buttons after all the regular ones, so I
    can get around it, but it would be good knowledge to have if my boss asks me
    to do more customization work or change the order around.

    You guys are great! Thanks for all the help.
    Trevor
  • edited June 2007

    Okay, so given that, you have two options:

    1. Descend from TppPreview, override CreateToolbarItems by calling
    inherited to create the default toolbar items and then add code to create
    custom items. (I would recommend this approach as it is the simplest.)

    2. Descend from TppCustomPreview (perhaps by copying the TppPreview class)
    which will give you more control with the trade off of requiring more code.


    --
    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com

    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited June 2007
    Ya, I kinda figured those would be the options. Just thought that you would
    like to know so if the intended functionality was to be able to insert the
    buttons by creating them in an overridden function that it isnt that
    possible. :)

    Thanks again!
    Trevor


This discussion has been closed.