Please enable JavaScript to view this site.

A-Shell Reference

Navigation: Development Topics

Dynamic Structures

Scroll Prev Top Next More

A Dynamic Structure (aka "Dynstruct") is like a regular structure—i.e., one defined with DEFSTRUCT—except that the definition occurs at runtime rather than compile time. This allows general-purpose compiled routines to adapt at run-time to a wide variety of data structures or record layouts, including ones not known about in advance. Typical applications include:

Generic file or audit trail viewers.
Report generators.
Handlers for SQL query results or CSV imports.
Security hardening of existing code (by modifying record structures at runtime to remove unauthorized fields without breaking code referencing the authorized fields).
Creating XTREE array layouts on the fly.
Decoupling field-level logic from the physical layout of the containing record, i.e. adopting a more SQL-like approach to data.

Dynamic Structures in A-Shell are implemented with the MX_DYNSTRUCT subroutine, which see for additional and related information.

Dynstruct's Four Steps

There are four steps to using dynamic structures:

Declare a Dynstruct variable to contain the structure
Reference the Dynstruct structure and members as you would traditional structures / members.

Typographical Note

The term "Dynstruct" is used here loosely as a shorthand for "dynamic structure" or for the A-Shell dynamic structure implementation in general. There is also a data type of the same name. When referring to it specifically, we’ll use all upper case (DYNSTRUCT), even though data type names in ASB source code are not case sensitive. Code examples may use DYNSTRUCT and dynstruct interchangeably.

History

2022 February, A-Shell 6.5.1711: Add Structure Definition Embedding (see following topic)

Subtopics

Declare a Dynstruct Variable

Define the Dynstruct Layout

Bind the Dynstruct to a Variable

Reference / Usage

Dynstruct Limitations

Dynstruct Error Handling

Dynamic Structure Examples