A Method Sample
Methods are written as C++ functions within a framing structure of proprietary statements. Here is an example of a Format Method that formats a certain kind of date:
FORMAT
METHOD __MyFormatDate__
/*
** MyFormatDate is called for a three-byte field
** comprising, byte by byte:
** year (0 - 255, relative to 1900)
** month (1 - 12)
** day (1 - 31)
*/
CODE
{
static const char *keyMonth[13] =
{"???", "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
int iYear, iMonth, iDay;
iYear = ((int)i64CurrentField & 0xFF) + 1900;
iMonth = ((int)i64CurrentField >> 8) & 0xFF;
if (iMonth > 12) iMonth = 0;
iDay = (int)i64CurrentField >> 16;
if (eParam1 == eDash)
csOutput.Format("%d-%s-%d", iDay, keyMonth[iMonth],
iYear);
else
csOutput.Format("%d/%d/%d", iMonth, iDay, iYear);
}
ENDCODE
PARAM "Format Preference" list {Dash Slash} = Dash
The variable i64CurrentField is a 64-bit integer that holds the value of the current field, that is the field decoded by the FIELD statement from which this method is invoked. i64CurrentField is one of several values that can be used by any Format Method. Others include the size of the field and a boolean indicating whether the result of the formatting is destined for the Summary Pane or the Decode Pane. The result of the format goes into an output variable called csOutput, an object of the type MFC CString.
Our MyFormatDate method has one parameter that determines whether the date is formatted as, for example, "30-May-2001" or "5/30/2001". The parameter is declared in the very last line, not at the start as you might expect:
PARAM "Format Preference" list {Dash Slash} = Dash
This says there is a parameter of type list with a default value of "Dash". Note that the parameter is not given a formal parameter name; rather, it is known by the fixed name eParam1.