display.isOpen()

display.isOpen()

Description

display.isOpen() returns whether the Rich Display File is currently open. A display file is opened explicitly with display.open(), or implicitly by pjs.defineDisplay() when the userOpen option is not set to true. It is closed by display.close() or when the function that defined it ends.

The method is typically used to guard an open() call, because opening a file that is already open throws error 1215, and screen I/O on a file that is closed throws error 1211.

Syntax

display.isOpen()

Parameters

None.

Return Value

Boolean - true if the display file is open; false if it has not been opened yet or has been closed.

Examples

Example 1: Check the State Before Opening and Closing

Shows the value returned at each stage of a user-controlled display file's life: before it is opened, while it is open, and after it is closed.

Prerequisite: a Rich Display File named customer.json with a record format named detail that contains the fields custno, custname, and balance, and a button whose response property is bound to an indicator field named exit.

pjs.defineDisplay("display", "customer.json", { userOpen: true }); // false: the file has not been opened yet if (!display.isOpen()) { display.open(); } display.detail.execute(); // Code to operate on the display file goes here // true: the file was opened above if (display.isOpen()) { display.close(); } console.log(display.isOpen()); // false: the file is now closed

Example 2: Share a Display File Between Functions

A module with several functions that each need the screen. The helper makes sure the file is open before every use, without knowing which function opened it first.

Prerequisite: a Rich Display File named customer.json with a record format named detail that contains the fields custno, custname, and balance, and a button whose response property is bound to an indicator field named exit.

pjs.defineDisplay("display", "customer.json", { userOpen: true, static: true }); function ensureOpen() { if (!display.isOpen()) display.open(); // Open only when needed } function showCustomer(number) { ensureOpen(); custno = number; display.detail.execute(); } function finish() { if (display.isOpen()) display.close(); // Close only if something opened it } showCustomer(1001); finish();

RPG Equivalent

%OPEN


Related Pages