OnBeforePrint

Hi,

I would change the value of a table field just before printing it (add a prefix).
I suppose that I must use the event OnBeforePrint. But how can I assign the new value which must be printed ?

Thank you.

Regards.

Groupir.

Comments

  • Groupir wrote: »
    Hi,

    I would change the value of a table field just before printing it (add a prefix).
    I suppose that I must use the event OnBeforePrint. But how can I assign the new value which must be printed ?

    Thank you.

    Regards.

    Groupir.

    Groupir,

    We had this same requirement just today. Here is how we solved it. We placed a Text object named mCLIENT_ORDER_DETAIL_COD_PRODUCTNO on our detail band; the text object was not bound to any field, it was just sitting there with nothing in it.

    Here is the code we added to the OnBeforePrint event:
    procedure DetailData1OnBeforePrint(Sender: TfrxComponent);
    begin                                      
       if <CLIENT_ORDER_DETAIL."COD_PRODUCTNO"> = '7Q32221-999-M-M' then begin
          mCLIENT_ORDER_DETAIL_COD_PRODUCTNO.Text := 'X-'+<CLIENT_ORDER_DETAIL."COD_PRODUCTNO">;                                        
       end else begin                                                                                                     
          mCLIENT_ORDER_DETAIL_COD_PRODUCTNO.Text := <CLIENT_ORDER_DETAIL."COD_PRODUCTNO">;
       end;       
    end;
    

    In this example, we chose to add the letter X in front of our SKU only if the SKU was 7Q32221-999-M-M, otherwise we simply printed the SKU.

    We chose to name the Text object this way (mCLIENT_ORDER_DETAIL_COD_PRODUCTNO) so that when we read the code we know what field we are playing with, but you could have name the field "Larry" or "Elvis" or any name you choose. The idea here is that we can use the OnBeforePrint event to dump anything we want into that field.

    Hope this helps.
    Regards,
    Tony.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.