Retrieve Individual Parameters

Explicit statements or calls must be made to retrieve the parameters passed to the SBX routine. This may seem like an extra step compared to languages, like C, which handle the parameter passing more directly (by setting it up at compile time). But it is actually similar in concept to the higher level, runtime-adaptable interfaces like ActiveX/COM, which provide the flexibility for the modules to examine their own interfaces at runtime. This adds a little overhead and some complexity, but allows the external modules to be much more resilient to version changes in one side independent of the other. For example, a subroutine may be designed initially with 3 parameters, but later additional features may be added that require another parameter. The updated subroutine can still work with older programs since it can see that only 3 parameters were passed and act accordingly. In fact, the older version of the subroutine can even still work with newer programs, since the additional parameter can be ignored. Or, it can report to the caller that there seems to be a version mismatch. All this makes it much easier to develop reusable subroutines independent of the applications that use them.

There are two different methods for retrieving parameters. The older method (deprecated as of Build 903 but still supported) uses the following subroutine:

xcall MIAMEX, MX_XCBDATAX, xcbadr, xcbget, <parm#>, <variable>

MX_XCBDATAX is a constant, defined in ASHINC:XCALL.BSI, specifying the opcode to MIAMEX.SBR. The first <parm#> is 1 (not 0.) The <variable> you specify should be mapped in a way that is "reasonably compatible" with the actual type and size passed to the subroutine, although conversions and truncations will be applied automatically if necessary. XCBADR is a pointer to the parameter list, and is set up automatically by xcall.bsi. XCBGET is another constant, also set up by xcall.bsi, which indicates the operation (get vs. put.)

The new method (Build 903+) uses one or both of these special Basic statements:

XGETARGS ARG1{,ARG2,...ARGN}

XGETARG <arg#>,ARG

The first statement (XGETARGS) retrieves (some or all of) the subroutine arguments into the corresponding variables. (The first argument is returned in ARG1, the second in ARG2, etc.) If more args were passed than you specify variables for, the extra arguments are ignored. Conversely, if you specify more ARG variables in the XGETARGS statement then were passed by the caller, the excess ARG variables are ignored. In either case, the operation is non-destructive to the original argument list, so you can later go back and retrieve (or re-retrieve) parameters using XGETARGS, XGETARG, or the original MX_XCBDATAX statements. XGETARG <arg#>,ARG performs the same function as XGETARGS except that it retrieves only the one argument (whose number is specified in <arg#>, with the first parameter being #1).

As with the original MX_XCBDATAX operation, variable type and size conversions will be made as necessary, within the bounds of reason.

If the subroutine supports different, incompatible parameter calling formats, it can examine the parameter count, type, and size information provided in the XCBCNT and XCBSTRUCT variables set up by ASHINC:XCALL.BSI and then use the appropriate XGETARG or XGETARGS statements.