Skip to main content
Version: 20 R7 BETA

VP Run offscreen area

VP Run offscreen area ( parameters : Object) : Mixed

ParameterTypeDescription
parametersObject->Object containing the offscreen area's attributes
ResultMixed<-.result property of the .onEvent object, or Null if does not return a value

Description

The VP Run offscreen area command creates an offscreen area in memory which can be used to process 4D View Pro area commands and functions.

In parameters object, pass any of the following optional properties. These properties will be available through the This command within the onEvent method and reference the instance:

PropertyTypeDescription
areatextThe name of the offscreen area. If omitted or null, a generic name is assigned (e.g., "OffscreenArea1").
onEventobject (formula)A callback method that will be launched when the offscreen area is ready. It can be either:
  • an onEvent function of a class, or
  • a Formula object
  • By default, the callback method is called on the On VP Ready, On Load, On Unload, On End URL Loading, On URL Loading Error, On VP Range Changed, or On Timer events. The callback method can be used to access the 4D View Pro form object variable.
    autoQuitbooleanTrue (default value) if the command must stop the formula execution when the On End URL Loading or On URL Loading Error events occur. If false, you must use the CANCEL or ACCEPT commands in the onEvent callback method.
    timeoutnumberMaximum time (expressed in seconds) before the area automatically closes if no event is generated. If set to 0, no limitation is applied. Default value: 60
    resultmixedResult of the processing (if any)
    <customProperty>mixedAny custom attribute to be available in the onEvent callback method.

    The following property is automatically added by the command if necessary:

    PropertyTypeDescription
    timeoutReachedbooleanAdded with true value if timeout has been exceeded

    The offscreen area is only available during the execution of the VP Run offscreen area command. It will automatically be destroyed once execution has ended.

    The following commands can be used in the callback method:

    • ACCEPT
    • CANCEL
    • SET TIMER
    • WA Evaluate JavaScript
    • WA EXECUTE JAVASCRIPT FUNCTION

    Example 1

    You want to create an offscreen 4D View Pro area and get the value of a cell:

    // cs.OffscreenArea class declaration 
    Class constructor ($path : Text)
    This.filePath:=$path

    // This function will be called on each event of the offscreen area
    Function onEvent()
    Case of
    :(FORM Event.code=On VP Ready)
    VP IMPORT DOCUMENT(This.area;This.filePath)
    This.result:=VP Get value(VP Cell(This.area;6;22))

    ALERT("The G23 cell contains the value: "+String(This.result))
    End case

    The OffscreenArea callback method:

    $o:=cs.OffscreenArea.new()
    $result:=VP Run offscreen area($o)

    Example 2

    You want to load a large document offscreen, wait for all calculations to complete evaluating, and export it as a PDF:

    //cs.OffscreenArea class declaration
    Class constructor($pdfPath : Text)
    This.pdfPath:=$pdfPath
    This.autoQuit:=False
    This.isWaiting:=False

    Function onEvent()
    Case of
    :(FORM Event.code=On VP Ready)
    // Document import
    VP IMPORT DOCUMENT(This.area;$largeDocument4VP)
    This.isWaiting:=True

    // Start a timer to verify if all calculations are finished.
    // If during this period the "On VP Range Changed" is thrown, the timer will be restarted
    // The time must be defined according to the computer configuration.
    SET TIMER(60)

    :(FORM Event.code=On VP Range Changed)
    // End of calculation detected. Restarts the timer
    If(This.isWaiting)
    SET TIMER(60)
    End if

    :(FORM Event.code=On Timer)
    // To be sure to not restart the timer if you call others 4D View command after this point
    This.isWaiting:=False



    // Stop the timer
    SET TIMER(0)

    // Start the PDF export
    VP EXPORT DOCUMENT(This.area;This.pdfPath;New object("formula";Formula(ACCEPT)))

    :(FORM Event.code=On URL Loading Error)

    CANCEL
    End case

    The OffscreenArea callback method:

    $o:=cs.OffscreenArea.new()

    $result:=VP Run offscreen area($o)

    See also

    Blog post: End of document loading