procedure TForm1.Button1Click(Sender: TObject);
// This is just an example program to show how to translate an EDI X12 130 file
// in Delphi with Framework EDI component
var
   oEdiDoc: IediDocument;
   oSchema: IediSchema;
   oSchemas: IediSchemas;
   oSegment: IediDataSegment;
   sSegmentID: string;
   sLoopID: string;
   nArea: Integer;
   sValue: string;
   sEdiFile: string;
   sSefFile: string;
   sPath: string;
   sN1LoopQlfr: string;

 
begin
   sEdiFile := '130.x12';
   sSefFile := '130_4010.SEF';
   sPath := Trim(GetCurrentDir) + '\';

   // CREATES EDI DOCUMENT OBJECT
   oEdidoc := coedidocument.Create;
 
   // THIS MAKES CERTAIN THAT FREDI ONLY USES THE SEF FILE PROVIDED, AND THAT IT DOES 
   // NOT USE ITS BUILT-IN STANDARD REFERENCE TABLE TO TRANSLATE THE EDI FILE.
   oSchemas := oEdiDoc.GetSchemas as IediSchemas;
   oSchemas.EnableStandardReference := false;
 
   // STOPS FREDI FROM KEEPING ALL THE SEGMENTS IN MEMORY
   oEdiDoc.CursorType := 1;
 
   // LOADS THE SEF FILE
   oEdidoc.LoadSchema(sPath + sSefFile,0);
 
   // LOADS THE EDI FILE
   oEdiDoc.LoadEdi(sPath + sEdiFile);
 
   // GETS THE FIRST DATA SEGMENT
   oSegment := oEdiDoc.FirstDataSegment as IediDataSegment;
 
   // LOOP THAT WILL TRAVERSE THRU THE EDI FILE FROM TOP TO BOTTOM
   // Only certain data elements are added to the ListBox1 for display 
   while oSegment <> Nil do begin
 
      // DATA SEGMENTS WILL BE IDENTIFIED BY THEIR ID, THE LOOP SECTION AND AREA
      // (OR TABLE) NUMBER THAT THEY ARE IN.
      nArea := oSegment.Area;
      sLoopID := oSegment.LoopSection;
      sSegmentID := oSegment.ID;
 
      if nArea = 0 then begin
         if sLoopID = '' then begin
            if sSegmentID = 'ISA' then begin
               sValue := oSegment.DataElementValue[1,0];     // Authorization Information Qualifier
               sValue := oSegment.DataElementValue[2,0];     // Authorization Information
               sValue := oSegment.DataElementValue[3,0];     // Security Information Qualifier
               sValue := oSegment.DataElementValue[4,0];     // Security Information
               sValue := oSegment.DataElementValue[5,0];     // Interchange ID Qualifier
               sValue := oSegment.DataElementValue[6,0];     // Interchange Sender ID
               sValue := oSegment.DataElementValue[7,0];     // Interchange ID Qualifier
               sValue := oSegment.DataElementValue[8,0];     // Interchange Receiver ID
               sValue := oSegment.DataElementValue[9,0];     // Interchange Date
               sValue := oSegment.DataElementValue[10,0];     // Interchange Time
               sValue := oSegment.DataElementValue[11,0];     // Interchange Control Standards Identifier
               sValue := oSegment.DataElementValue[12,0];     // Interchange Control Version Number
               ListBox1.Items.Add(oSegment.DataElement[13].Description + ' = ' + oSegment.DataElementValue[13,0]);     // Interchange Control Number
               sValue := oSegment.DataElementValue[14,0];     // Acknowledgment Requested
               sValue := oSegment.DataElementValue[15,0];     // Usage Indicator
               sValue := oSegment.DataElementValue[16,0];     // Component Element Separator
            end
            else if sSegmentID = 'GS' then begin
               sValue := oSegment.DataElementValue[1,0];     // Functional Identifier Code
               sValue := oSegment.DataElementValue[2,0];     // Application Sender's Code
               sValue := oSegment.DataElementValue[3,0];     // Application Receiver's Code
               sValue := oSegment.DataElementValue[4,0];     // Date
               sValue := oSegment.DataElementValue[5,0];     // Time
               ListBox1.Items.Add(oSegment.DataElement[6].Description + ' = ' + oSegment.DataElementValue[6,0]);     // Group Control Number
               sValue := oSegment.DataElementValue[7,0];     // Responsible Agency Code
               sValue := oSegment.DataElementValue[8,0];     // Version / Release / Industry Identifier Code
            end;   //sSegmentID
         end;   //sLoopID
      end
      else if nArea = 1 then begin
         if sLoopID = '' then begin
            if sSegmentID = 'ST' then begin
               sValue := oSegment.DataElementValue[1,0];     // Transaction Set Identifier Code
               ListBox1.Items.Add(oSegment.DataElement[2].Description + ' = ' + oSegment.DataElementValue[2,0]);     // Transaction Set Control Number
            end
            else if sSegmentID = 'BGN' then begin
               sValue := oSegment.DataElementValue[1,0];     // Transaction Set Purpose Code
               ListBox1.Items.Add(oSegment.DataElement[2].Description + ' = ' + oSegment.DataElementValue[2,0]);     // Reference Identification
               sValue := oSegment.DataElementValue[3,0];     // Date
               sValue := oSegment.DataElementValue[4,0];     // Time
               sValue := oSegment.DataElementValue[5,0];     // Time Code
            end
            else if sSegmentID = 'ERP' then begin
               sValue := oSegment.DataElementValue[1,0];     // Transaction Type Code
               sValue := oSegment.DataElementValue[2,0];     // Status Reason Code
            end
            else if sSegmentID = 'REF' then begin
               sValue := oSegment.DataElementValue[1,0];     // Reference Identification Qualifier
               ListBox1.Items.Add(oSegment.DataElement[2].Description + ' = ' + oSegment.DataElementValue[2,0]);     // Reference Identification
            end;   //sSegmentID
         end
         else if sLoopID = 'N1' then begin
            // If loop has more that one instance, then you should check for the qualifier that differentiates the loop instances here e.g.
            If sSegmentID = 'N1' then begin
               sN1LoopQlfr := oSegment.DataElementValue[1,0];   // In most cases the loop qualifier is the first element of the first segment in the loop, but not necessarily
            end;
            If sN1LoopQlfr = 'AS' then begin //Postsecondary Education Sender
                if sSegmentID = 'N1' then begin
                   sValue := oSegment.DataElementValue[1,0];     // Entity Identifier Code
                   ListBox1.Items.Add(oSegment.DataElement[2].Description + ' Sender = ' + oSegment.DataElementValue[2,0]);     // Name
                end
                else if sSegmentID = 'N3' then begin
                   sValue := oSegment.DataElementValue[1,0];     // Address Information
                end
                else if sSegmentID = 'N4' then begin
                   sValue := oSegment.DataElementValue[1,0];     // City Name
                end;   //sSegmentID
            end
            else if sN1LoopQlfr = 'AT' then begin //Postsecondary Education Receiver
                if sSegmentID = 'N1' then begin
                   sValue := oSegment.DataElementValue[1,0];     // Entity Identifier Code
                   ListBox1.Items.Add(oSegment.DataElement[2].Description + ' Receiver = ' + oSegment.DataElementValue[2,0]);     // Name
                end
                else if sSegmentID = 'N3' then begin
                   sValue := oSegment.DataElementValue[1,0];     // Address Information
                end
                else if sSegmentID = 'N4' then begin
                   sValue := oSegment.DataElementValue[1,0];     // City Name
                end;   //sSegmentID
            end;
         end
         else if sLoopID = 'IN1' then begin
            if sSegmentID = 'IN1' then begin
               sValue := oSegment.DataElementValue[1,0];     // Entity Type Qualifier
               sValue := oSegment.DataElementValue[2,0];     // Name Type Code
            end
            else if sSegmentID = 'IN2' then begin
               sValue := oSegment.DataElementValue[1,0];     // Name Component Qualifier
               ListBox1.Items.Add(oSegment.DataElement[2].Description + ' = ' + oSegment.DataElementValue[2,0]);     // Name
            end;   //sSegmentID
         end
         else if sLoopID = 'SST' then begin
            if sSegmentID = 'SST' then begin
               sValue := oSegment.DataElementValue[1,0];     // Status Reason Code
               sValue := oSegment.DataElementValue[2,0];     // Date Time Period Format Qualifier
               sValue := oSegment.DataElementValue[3,0];     // Date Time Period
            end
            else if sSegmentID = 'N1' then begin
               sValue := oSegment.DataElementValue[1,0];     // Entity Identifier Code
               ListBox1.Items.Add(oSegment.DataElement[2].Description + ' = ' + oSegment.DataElementValue[2,0]);     // Name
            end
            else if sSegmentID = 'N4' then begin
               ListBox1.Items.Add(oSegment.DataElement[1].Description + ' = ' + oSegment.DataElementValue[1,0]);     // City Name
               ListBox1.Items.Add(oSegment.DataElement[2].Description + ' = ' + oSegment.DataElementValue[2,0]);     // State or Province Code
            end;   //sSegmentID
         end
         else if sLoopID = 'ATV' then begin
            if sSegmentID = 'ATV' then begin
               sValue := oSegment.DataElementValue[1,0];     // Code List Qualifier Code
               sValue := oSegment.DataElementValue[2,0];     // Industry Code
               ListBox1.Items.Add(oSegment.DataElement[3].Description + ' = ' + oSegment.DataElementValue[3,0]);     // Entity Title
            end
            else if sSegmentID = 'DTP' then begin
               sValue := oSegment.DataElementValue[1,0];     // Date/Time Qualifier
               sValue := oSegment.DataElementValue[2,0];     // Date Time Period Format Qualifier
               ListBox1.Items.Add(oSegment.DataElement[3].Description + ' = ' + oSegment.DataElementValue[3,0]);     // Date Time Period
            end;   //sSegmentID
         end
         else if sLoopID = 'TST' then begin
            if sSegmentID = 'TST' then begin
               sValue := oSegment.DataElementValue[1,0];     // Educational Test or Requirement Code
               ListBox1.Items.Add(oSegment.DataElement[2].Description + ' = ' + oSegment.DataElementValue[2,0]);     // Name
               sValue := oSegment.DataElementValue[3,0];     // Date Time Period Format Qualifier
               ListBox1.Items.Add(oSegment.DataElement[4].Description + ' = ' + oSegment.DataElementValue[4,0]);     // Date Time Period
               sValue := oSegment.DataElementValue[5,0];     // Reference Identification
               sValue := oSegment.DataElementValue[6,0];     // Reference Identification
               sValue := oSegment.DataElementValue[7,0];     // Level of Individual, Test, or Course Code
            end;   //sSegmentID
         end
         else if sLoopID = 'TST;SBT' then begin
            if sSegmentID = 'SBT' then begin
               sValue := oSegment.DataElementValue[1,0];     // Subtest Code
            end
            else if sSegmentID = 'SRE' then begin
               sValue := oSegment.DataElementValue[1,0];     // Test Score Qualifier Code
               sValue := oSegment.DataElementValue[2,0];     // Description
            end;   //sSegmentID
         end;   //sLoopID
      end
      else if nArea = 2 then begin
         if sLoopID = 'LX' then begin
            if sSegmentID = 'LX' then begin
               sValue := oSegment.DataElementValue[1,0];     // Assigned Number
            end
            else if sSegmentID = 'HS' then begin
               sValue := oSegment.DataElementValue[1,0];     // Health Screening Type Code
               sValue := oSegment.DataElementValue[2,0];     // Date Time Period Format Qualifier
               ListBox1.Items.Add(oSegment.DataElement[3].Description + ' = ' + oSegment.DataElementValue[3,0]);     // Date Time Period
               sValue := oSegment.DataElementValue[4,0];     // Status Reason Code
            end
            else if sSegmentID = 'IMM' then begin
               ListBox1.Items.Add(oSegment.DataElement[1].Description + ' = ' + oSegment.DataElementValue[1,0]);     // Immunization Type Code
               sValue := oSegment.DataElementValue[2,0];     // Date Time Period Format Qualifier
               ListBox1.Items.Add(oSegment.DataElement[3].Description + ' = ' + oSegment.DataElementValue[3,0]);     // Date Time Period
            end;   //sSegmentID
         end
         else if sLoopID = 'LX;SES' then begin
            if sSegmentID = 'SES' then begin
               sValue := oSegment.DataElementValue[1,0];     // Date Time Period
               sValue := oSegment.DataElementValue[2,0];     // Count
               sValue := oSegment.DataElementValue[3,0];     // Date Time Period
               sValue := oSegment.DataElementValue[4,0];     // Session Code
               ListBox1.Items.Add(oSegment.DataElement[5].Description + ' = ' + oSegment.DataElementValue[5,0]);     // Name
               sValue := oSegment.DataElementValue[6,0];     // Date Time Period Format Qualifier
               sValue := oSegment.DataElementValue[7,0];     // Date Time Period
               sValue := oSegment.DataElementValue[8,0];     // Date Time Period Format Qualifier
               sValue := oSegment.DataElementValue[9,0];     // Date Time Period
               sValue := oSegment.DataElementValue[10,0];     // Level of Individual, Test, or Course Code
               sValue := oSegment.DataElementValue[11,0];     // Identification Code Qualifier
               sValue := oSegment.DataElementValue[12,0];     // Identification Code
               sValue := oSegment.DataElementValue[13,0];     // Name
               sValue := oSegment.DataElementValue[14,0];     // Status Reason Code
            end;   //sSegmentID
         end
         else if sLoopID = 'LX;SES;CRS' then begin
            if sSegmentID = 'CRS' then begin
               sValue := oSegment.DataElementValue[1,0];     // Basis for Academic Credit Code
               sValue := oSegment.DataElementValue[2,0];     // Academic Credit Type Code
               sValue := oSegment.DataElementValue[3,0];     // Quantity
               sValue := oSegment.DataElementValue[4,0];     // Quantity
               sValue := oSegment.DataElementValue[5,0];     // Academic Grade Qualifier
               sValue := oSegment.DataElementValue[6,0];     // Academic Grade
               sValue := oSegment.DataElementValue[7,0];     // Yes/No Condition or Response Code
               sValue := oSegment.DataElementValue[8,0];     // Academic Grade or Course Level Code
               sValue := oSegment.DataElementValue[9,0];     // Course Repeat or No Count Indicator Code
               sValue := oSegment.DataElementValue[10,0];     // Identification Code Qualifier
               sValue := oSegment.DataElementValue[11,0];     // Identification Code
               sValue := oSegment.DataElementValue[12,0];     // Quantity
               sValue := oSegment.DataElementValue[13,0];     // Level of Individual, Test, or Course Code
               sValue := oSegment.DataElementValue[14,0];     // Name
               ListBox1.Items.Add(oSegment.DataElement[15].Description + ' = ' + oSegment.DataElementValue[15,0]);     // Reference Identification
               sValue := oSegment.DataElementValue[16,0];     // Name
            end;   //sSegmentID
         end;   //sLoopID
      end;  //nArea
 
      // GETS THE NEXT DATA SEGMENT
      oSegment := oSegment.Next as IediDataSegment;
   end;

   ShowMessage('Done.');
end;