CurContext() function - MapBasic - 2023

MapInfo MapBasic Reference

Product type
Software
Portfolio
Locate
Product family
MapInfo
Product
MapInfo > MapBasic
Version
2023
Language
English
Product name
MapBasic
Title
MapInfo MapBasic Reference
First publish date
1985
Last updated
2023-09-12
Published on
2023-09-12T16:32:32.686312

Smart text in a text frame needs to be able to refer to the current layout window, the current page that the text frame is on, and the text frame's current index into the collection of frames on the current page in order to use various MapBasic functions. This function provides this information that is valid only within a piece of Smart Text.

Syntax
CurContext(context_attribute)
Return Value

Integer

Description

Returns information related to the current Layout text frame. Depending on the attribute passed, returns the current Layout window identifier, the current page that the text frame is on, or the text frame's current index into the collection of frames on the current page. This function is valid only within a Smart Text expression in a text frame.

Currently supports 3 attributes as arguments:

Frame Type ID Frame Description
CONTEXT_WINDOWID 1 returns the WINDOW id of the Layout with the text frame containing the Smart Text.
CONTEXT_PAGENUMBER 2 returns the page number (1-based) of the text frame containing the Smart Text.
CONTEXT_FRAMENUMBER 3 returns the frame number (1-based) of the text frame containing the Smart Text.
CONTEXT_MAPWINDOWID 4 returns the map window currently being drawn.

Example SmartText strings using CurContext

Note: In smart text expressions, the value of the attribute must be used, not its name.
  1. Displays "Page x of y"
    Page $mb{LayoutInfo(CurContext(1), 12} of $mb{LayoutInfo(CurContext(1), 11}

    After the smart text, which is on page 1 of a 2 page Layout, is evaluated, the following displays:

    Page 1 of 2
  2. Displays Name property of text frame
    $mb{LayoutItemInfo(CurContext(1), CurContext(3), 14}

    If you set the text frame's Name property to Main Title, when Smart text is evaluated, the following displays:

    Main Title
Note: If you use CurContext in a MapBasic window or a MapBasic program, and it is not within a SmartText expression in a Layout text frame, the following error appears:
CurContext may only be used within a Smart Text expression in a Layout Text frame.