Impedir la impresión desde una vista previa del informe en Visual FoxPro 9.0

En este artículo se muestra cómo deshabilitar la opción para imprimir un informe mientras se está viendo en versión preliminar mediante Object-Assisted Informes en Visual FoxPro 9.0.

Versión original del producto: Visual FoxPro
Número de KB original: 895279

Resumen

Microsoft Visual FoxPro 9.0 presenta Object-Assisted arquitectura de informes. Con este nuevo diseño, puede interactuar directamente a través del código con las herramientas de informes de Visual FoxPro 9.0, como las Diseñador de informes y las vistas previas de informes. Por lo tanto, es más fácil deshabilitar la capacidad de imprimir desde una vista previa del informe en Visual FoxPro 9.0 que en versiones anteriores de Visual FoxPro. En este artículo se describe cómo escribir código para interactuar directamente con y configurar Object-Assisted vistas previas del informe de informes.

Más información

De forma predeterminada, cuando se obtiene una vista previa de un informe de Object-Assisted en Visual FoxPro 9.0, el usuario puede imprimir el informe desde la ventana Vista previa del informe mediante cualquiera de los métodos siguientes:

  • En la barra de herramientas Vista previa del informe, haga clic en el botón Imprimir .
  • Haga clic con el botón derecho en la ventana Vista previa del informe y, a continuación, haga clic en Imprimir.

Es posible que desee deshabilitar esta opción. En versiones anteriores de Visual FoxPro, el archivo de recursos de Visual FoxPro (FoxUser.dbf) tenía que cambiarse.

En Visual FoxPro 9.0, todavía puede cambiar el archivo FoxUser.dbf para deshabilitar la impresión desde la ventana Vista previa del informe. Sin embargo, con la introducción de Object-Assisted Informes, ya está disponible un enfoque alternativo. De forma predeterminada, Object-Assisted Informes en Visual FoxPro 9.0 no está habilitado. Para habilitarlo, tiene que cambiar la REPORTBEHAVIOR configuración. Para ello, use uno de los métodos siguientes:

  • Método 1, cambie la configuración de comportamiento del motor de informes mediante el IDE de Visual FoxPro:

    1. En el menú Herramientas, haga clic en Opciones.
    2. En el cuadro de diálogo Opciones , haga clic en la pestaña Informes y, a continuación, seleccione 90 (Asistido por objetos) en la lista Comportamiento del motor de informes.
    3. (Opcional) Si desea que esta configuración persista entre sesiones de Visual FoxPro 9.0, haga clic en Establecer como predeterminado en el cuadro de diálogo Opciones .
  • Método 2, ejecute el siguiente comando en el código para habilitar Object-Assisted Informes:

    SET REPORTBEHAVIOR 90.

Ejemplo de código

Al ejecutar el ejemplo de código siguiente, se obtiene una vista previa del archivo de informe de ejemplo denominado Colors.frx. El ejemplo de código muestra una vista previa del informe y usa una combinación de la configuración de propiedades en el contenedor de vista previa y el controlador de extensión de vista previa para deshabilitar completamente la impresión desde la ventana Vista previa del informe.

Este ejemplo de código también soluciona un problema en visual FoxPro 9.0 Object-Assisted vista previa del informe donde la barra de herramientas Vista previa del informe no conserva correctamente la configuración de presentación entre apariencias en la misma sesión de vista previa de informe.

Este ejemplo de código se aplica tanto al entorno de desarrollo de Visual FoxPro 9.0 como a los ejecutables creados mediante Visual FoxPro 9.0, siempre y cuando se use Object-Assisted Informes.

Para usar este ejemplo de código, siga estos pasos:

  1. Guarde el código siguiente en un nuevo archivo de programa en Visual FoxPro 9.0 y, a continuación, ejecute el código.

    *----------- START CODE
    *
    *-----------------------------------
    * AUTHOR: Trevor Hancock
    * CREATED: 02/24/05 02:47:08 PM
    * ABSTRACT:
    * Shows how to disable printing from
    * PREVIEW when you use object-assisted
    * reporting in VFP9.
    *
    * Also includes a workaround for problem
    * where the PREVIEW toolbar does not
    * recognize the TextOnToolbar or
    * PrintFromPreview settings between
    * toolbar displays during same preview.
    *-----------------------------------
    
    *-- Defines whether to alllow for
    *-- printing during preview. Used to set
    *-- the "AllowPrintfromPreview" property
    *-- of the object-assisted preview container
    *-- later in this code.
    #DEFINE PrintFromPreview .T.
    
    LOCAL loPreviewContainer AS FORM, ;
    loReportListener AS REPORTLISTENER, ;
    loExHandler AS ExtensionHandler OF SYS(16)
    
    *-- Get a preview container from the
    *-- .APP registered to handle object-assisted
    *-- report previewing.
    loPreviewContainer = NULL
    DO (_REPORTPREVIEW) WITH loPreviewContainer
    *-- Create a PREVIEW listener
    loReportListener = NEWOBJECT('ReportListener')
    loReportListener.LISTENERTYPE = 1 &&Preview
    
    *-- Link the Listener and preview container
    loReportListener.PREVIEWCONTAINER = loPreviewContainer
    
    *-- Changing this property prevents printing from the Preview toolbar
    *-- and from right-clicking on the preview container, and then clicking "print".
    *-- This property is not in the VFP9 documentation at this point.
    loPreviewContainer.AllowPrintfromPreview = PrintFromPreview
    *-- Controls appearance of text on some of the
    *-- Preview toolbar buttons. .F. is the default.
    *-- Included here just to show that it is an available option.
    loPreviewContainer.TextOnToolbar = .F.
    
    *-- Create an extension handler and hook it to the
    *-- preview container. This will let you manipulate
    *-- properties of the container and its Preview toolbar
    loExHandler = NEWOBJECT('ExtensionHandler')
    loPreviewContainer.SetExtensionHandler( loExHandler )
    
    REPORT FORM ;
    HOME() + 'Samples\Solution\Reports\colors.frx' ;
    OBJECT loReportListener
    
    RELEASE loPreviewContainer, loReportListener, loExHandler
    
    *-------------------------
    *-------------------------
    DEFINE CLASS ExtensionHandler AS CUSTOM
    *-- Ref to the Preview Container's Preview Form
    PreviewForm = NULL
    
    *-- Here you implement (hook into) the PreviewForm_Assign
    *-- event of the preview container's parent proxy
    PROCEDURE PreviewForm_Assign( loRef )
    *-- Perform default behavior: assign obj ref.
    THIS.PreviewForm = loRef
    
    *-- Grab the obj ref to the preview form and bind to its
    *-- ShowToolbar() method. This lets the
    *-- STB_Handler() method of this extension handler
    *-- to run code whenever the Preview toolbar is shown
    *-- by the PreviewForm.ShowToolbar() method.
    IF !ISNULL( loRef )
    BINDEVENT(THIS.PreviewForm, ;
    'ShowToolbar', THIS, 'STB_Handler')
    ENDIF
    ENDPROC
    
    PROCEDURE STB_Handler(lEnabled)
    *-- Here you work around the setting
    *-- persistence problem in the Preview toolbar. 
    *-- The Preview toolbar class (frxpreviewtoolbar)
    *-- already has code that you can use to enforce
    *-- setting's persistence; it is just not called. Here,
    *-- you call it.
    WITH THIS.PreviewForm.TOOLBAR
    .REFRESH()
    *-- When you call frxpreviewtoolbar::REFRESH(), the
    *-- toolbar caption is set to its Preview form,
    *-- which differs from typical behavior. You must revert that
    *-- to be consistent. If you did not do this,
    *-- you would see " - Page 2" appended to the toolbar
    *-- caption if you skipped pages.
    .CAPTION = THIS.PreviewForm.formCaption
    ENDWITH
    ENDPROC
    
    *-- A preview container requires these methods
    *-- to be implemented in an associated preview extension handler.
    *-- They are not used in this example, but still must be here.
    PROCEDURE AddBarsToMenu( cPopup, iNextBar )
    PROCEDURE SHOW( iStyle )
    ENDPROC
    PROCEDURE HandledKeyPress( nKeyCode, nShiftAltCtrl )
    RETURN .F.
    ENDPROC
    PROCEDURE PAINT
    ENDPROC
    PROCEDURE RELEASE
    RETURN .T.
    ENDPROC ENDDEFINE
    *
    *
    *----------- END CODE
    

    Se abrirá una vista previa del informe Colors.frx.

    Nota:

    Para imprimir desde la ventana Vista previa del informe, haga clic con el botón derecho en la vista previa o haga clic en Imprimir en la barra de herramientas Vista previa del informe.

  2. Cierre la vista previa y, a continuación, modifique el código en el editor de programas.

  3. Cambie la instrucción #DEFINE de la parte superior del código a un valor de .F. Para ello, busque el código siguiente.

    #DEFINE PrintFromPreview .T.
    

    Reemplácelo por el código siguiente:

    #DEFINE PrintFromPreview .F.
    
  4. Guarde el código y vuelva a ejecutarlo.

Nota:

Ahora no puede imprimir desde la ventana Vista previa del informe haciendo clic con el botón derecho en la vista previa o haciendo clic en Imprimir en la barra de herramientas Vista previa del informe.