Online Help TEDILoopStack

Unit JclEDI

Types

TEDILoopStack

   The TEDILoopStack object is designed to keep track of the implicit nesting of segments and assist in building an object hierarchy as an EDI document object formats a TEDITransactionSet or TEDIMessage type object.

 Type

TEDILoopStackRecord = record
  SegmentId: string;
  SpecStartIndex: Integer;
  OwnerLoopId: string;
  ParentLoopId: string;
  EDIObject: TEDIObject;
  EDISpecObject: TEDIObject;
end;

   The TEDILoopStack is designed to contain an array of records of type TEDILoopStackRecord.

 Type

TEDILoopStackArray = array of TEDILoopStackRecord;

   The TEDILoopStackArray is what is treated as a stack. When TEDILoopStack is used, items (records) will be pushed and popped from the stack (array).

 Function

function ValidateLoopStack(SegmentId, OwnerLoopId, ParentLoopId: string;
  StartIndex: Integer; EDIObject: TEDIObject): TEDILoopStackRecord;

SegmentId - The segment id where a loop first starts.
OwnerLoopId - The loop the segment belongs to.
ParentLoopId - The loop the segment is nested in.
StartIndex - A pass through value used to indicate the index of the specification from a tabular data source.
EDIObject - Typically the current EDI-Loop based object that is the owner of other objects for the iteration of the loop (in code).

   EDI document type objects use the TEDILoopStack while looping (in code) through a table (array) of data and a table (array) of specifications at the same time. While going through each loop, the EDI document class calls the TEDILoopStack.ValidateLoopStack function. Based on the input data, this function handles most of the management of the TEDILoopStackArray thus pushing, popping, and updating the stack as needed.

   The ValidateLoopStack function must be called once prior to the EDI document looping in order to initialize the stack and set the base container object.

 Type

TEDILoopStackOnAddLoopEvent = procedure(StackRecord: TEDILoopStackRecord;
  SegmentId, OwnerLoopId, ParentLoopId: string;
  var EDIObject: TEDIObject) of object;

   In order for an EDI document type object to build an object hierarchy from the EDI data and specification file, a TEDILoopStackOnAddLoopEvent event handler should be assigned to the TEDILoopStack.OnAddLoop property. The TEDILoopStack object not only keeps track of the nesting of segments and loops but also knows when to create a new EDI-Loop type object.

   The event handler will be responsible for creating new EDI-Loop objects, assigning any loop values such as Id, and returning the new loop object through the var EDIObject parameter. After the event is handled the EDIObject will be added or updated to the stack thus becoming the current EDI-Loop object (or container) for other objects during the EDI document looping (in code) process.

 Type

TEDILoopStackFlags = (ediAltStackPointer, ediStackResized, ediLoopRepeated); TEDILoopStackFlagSet = set of TEDILoopStackFlags;

   There are a few internal flags in this class that are important to know.

ediLoopRepeated - When this flag is set in ValidateLoopStack and the TEDILoopStack.OnAddLoop property is assigned, then only the EDI-Loop based object is added and updated to the stack. The reason for this is that the stack is only supposed to increase or decrease depending on the nesting of the current specification record within the total specification document. If the loop repeats only the current EDI-Loop object (or container) needs to be assigned. This should be the only flag that the developer may need to modify.

ediStackResized - This flag is managed internally by the TEDILoopStack object. The ediStackResized flag is set when stack entries have been popped from the stack.

ediAltStackPointer - This flag is managed internally by the TEDILoopStack object. The ediAltStackPointer flag indicates that the ValidateLoopStack function has returned to any previous level in the stack and that multiple stack entries have been popped from the stack.

   Other miscellaneous notes:

   When entries are popped from the stack EDI-Loop objects are not freed. This is correct because the EDI document object (object hierarchy) that is being built must manage the objects, the stack is not supposed to manage the objects.

   Bad input from the specification data in the EDI document object may cause incorrect branching in the object hierarchy. This is most likely caused by passing incorrect data for OwnerLoopId and ParentLoopId when ValidateLoopStack was called in the EDI document object.

   The best way to understand what is happening to the stack is to uncomment the debug code and step through it.

Usage

Notes & Examples

See the following for implementation examples:
  JclEDI_ANSIX12.TEDITransactionSetDocument
  JclEDI_ANSIX12_Ext.TEDI_ANSIX12_Document
  JclEDI_UNEDIFACT_Ext.TEDI_UNEDIFACT_Document