procedure TForm1.cmdTranslateClick(Sender: TObject);
   //This is just an example program to demonstrate how to translate an UN/EDIFACT INVOIC file
   //in Delphi using Framework EDI component

var
   oEdiDoc : IediDocument;
   oSegment : IediDataSegment;
   oSchemas : IediSchemas;

   sPath : string;
   sPartyEntity : string;
   sSefFile : string;
   sEdiFile : string;
   sSegmentID : string;
   nArea : integer;
   sLoopSection : string;
   sValue : string;


begin

   cmdTranslate.Enabled := False;

   sPath := Trim(GetCurrentDir) + '\';'
   sSefFile := sPath + 'INVOIC_S93A.SEF';
   sEdiFile := sPath + 'INVOIC.TXT';

   //instantiate edi document object
   oEdiDoc := CoediDocument.Create();

   //change cursor type to ForwardOnly sa as to save RAM and improve performance
   oEdiDoc.CursorType := 1;

   //disable internal Standard Reference Library to save RAM and improve performance
   oSchemas := oEdiDoc.GetSchemas as IediSchemas;
   oSchemas.EnableStandardReference := false;

   //set terminators
   oEdiDoc.SegmentTerminator := '''';
   oEdiDoc.ElementTerminator := '+';
   oEdiDoc.CompositeTerminator := ':';
   oEdiDoc.ReleaseIndicator := '?';

   //load SEF file
   oEdidoc.LoadSchema(sSefFile,0);

   //load EDI file
   oEdiDoc.LoadEdi(sEdiFile);

   //traverse through entire EDI file from top segment to bottom segment a segment at a time
   oSegment := oEdiDoc.FirstDataSegment as IediDataSegment;     //get first data segment
   while oSegment <> Nil do begin
      //identify segments by their area, loop section they are in, and their ID.
      nArea := oSegment.Area;
      sLoopSection := oSegment.LoopSection;
      sSegmentID := oSegment.ID;

      if nArea = 0 then begin
        if sSegmentID = 'UNB' then begin
               sValue := oSegment.DataElementValue[1,1];     // Syntax identifier
               sValue := oSegment.DataElementValue[1,2];     // Syntax version number
               sValue := oSegment.DataElementValue[1,3];     // Service code list directory version number
               sValue := oSegment.DataElementValue[1,4];     // Character encoding, coded
               sValue := oSegment.DataElementValue[2,1];     // Interchange sender identification
               sValue := oSegment.DataElementValue[2,2];     // Partner identification code qualifier
               sValue := oSegment.DataElementValue[2,3];     // Interchange sender internal identification
               sValue := oSegment.DataElementValue[2,4];     // Interchange sender internal sub-identification
               sValue := oSegment.DataElementValue[3,1];     // Recipient identification
               sValue := oSegment.DataElementValue[3,2];     // Partner identification code qualifier
               sValue := oSegment.DataElementValue[3,3];     // Routing address
               sValue := oSegment.DataElementValue[3,4];     // Interchange Recipient Internal Sub-Identification
               sValue := oSegment.DataElementValue[4,1];     // Date
               sValue := oSegment.DataElementValue[4,2];     // Time
               ListBox1.Items.Add(oSegment.DataElement[5].Description + ' = ' + oSegment.DataElementValue[5,0]);  //ISA INTERCHANGE CONTROL NO.
               sValue := oSegment.DataElementValue[6,1];     // Recipient reference/password
               sValue := oSegment.DataElementValue[6,2];     // Recipient's reference/password qualifier
               sValue := oSegment.DataElementValue[7,0];     // Application reference
               sValue := oSegment.DataElementValue[8,0];     // Processing priority code
               sValue := oSegment.DataElementValue[9,0];     // Acknowledgement request
               sValue := oSegment.DataElementValue[10,0];     // Interchange Agreement Identifier
               sValue := oSegment.DataElementValue[11,0];     // Test indicator
        end;

      end
      else if nArea = 1 then begin
         if sLoopSection = '' then begin
            if sSegmentID = 'UNH' then begin
               ListBox1.Items.Add(oSegment.DataElement[1].Description + ' = ' + oSegment.DataElementValue[1,0]);     // Message reference number
               sValue := oSegment.DataElementValue[2,1];     // Message type identifier
               sValue := oSegment.DataElementValue[2,2];     // Message version number
               sValue := oSegment.DataElementValue[2,3];     // Message release number
               sValue := oSegment.DataElementValue[2,4];     // Controlling agency
               sValue := oSegment.DataElementValue[2,5];     // Association assigned code

            end
            else if sSegmentID = 'BGM' then begin
               sValue := oSegment.DataElementValue[1,1];     // Document/message name, coded
               sValue := oSegment.DataElementValue[1,2];     // Code list qualifier
               sValue := oSegment.DataElementValue[1,3];     // Code list responsible agency, coded
               sValue := oSegment.DataElementValue[1,4];     // Document/message name
               ListBox1.Items.Add(oSegment.DataElement[2].Description + ' = ' + oSegment.DataElementValue[2,0]);  //INVOICE NO.
               sValue := oSegment.DataElementValue[3,0];     // Message function, coded
            end
            else if sSegmentID = 'DTM' then begin
               sValue := oSegment.DataElementValue[1,1];     // Date/time/period qualifier
               ListBox1.Items.Add(oSegment.DataElement[1].Description + ' = ' + oSegment.DataElementValue[1,2]);  //INVOICE DATE.
               sValue := oSegment.DataElementValue[1,3];     // Date/time/period format qualifier
            end;
         end  //sLoopSection = ''
         else if sLoopSection = 'RFF' then begin
            if sSegmentID = 'RFF' then begin
               sValue := oSegment.DataElementValue[1,1];     // Reference qualifier
               ListBox1.Items.Add(oSegment.DataElement[1].Description + ' = ' + oSegment.DataElementValue[1,2]);  //ORDER NO
               sValue := oSegment.DataElementValue[1,3];     // Line number
            end;
         end
         else if sLoopSection = 'NAD' then begin
             //if loops has multiple instances, then first identify them by checking their qualifier
             if sSegmentID = 'NAD' then begin
                sPartyEntity := oSegment.DataElementValue[1,0];   //Get qualifier value.  We will be checking for RE,ST OR BY
             end;

             if sPartyEntity = 'RE' then begin  //Remit-to address
                if sSegmentID = 'NAD' then begin
                   sValue := oSegment.DataElementValue[1,0];     // Party qualifier
                   sValue := oSegment.DataElementValue[2,1];     // Party identification
                   sValue := oSegment.DataElementValue[2,2];     // Code list qualifier
                   sValue := oSegment.DataElementValue[2,3];     // Code list responsible agency, coded
                   sValue := oSegment.DataElementValue[3,1];     // Name and address line
                   sValue := oSegment.DataElementValue[3,2];     // Name and address line
                   sValue := oSegment.DataElementValue[3,3];     // Name and address line
                   sValue := oSegment.DataElementValue[3,4];     // Name and address line
                   sValue := oSegment.DataElementValue[3,5];     // Name and address line
                   ListBox1.Items.Add(oSegment.DataElement[4].Description + ' = ' + oSegment.DataElementValue[4,1]);   //MANUFACTURER NAME                sValue := oSegment.DataElementValue[4,2];     // Party name
                   sValue := oSegment.DataElementValue[4,3];     // Party name
                end;
             end
             else if sPartyEntity = 'ST' then begin  //Ship-To address
                if sSegmentID = 'NAD' then begin
                   sValue := oSegment.DataElementValue[1,0];     // Party qualifier
                   sValue := oSegment.DataElementValue[2,1];     // Party identification
                   sValue := oSegment.DataElementValue[2,2];     // Code list qualifier
                   sValue := oSegment.DataElementValue[2,3];     // Code list responsible agency, coded
                   sValue := oSegment.DataElementValue[3,1];     // Name and address line
                   sValue := oSegment.DataElementValue[3,2];     // Name and address line
                   sValue := oSegment.DataElementValue[3,3];     // Name and address line
                   sValue := oSegment.DataElementValue[3,4];     // Name and address line
                   sValue := oSegment.DataElementValue[3,5];     // Name and address line
                   ListBox1.Items.Add(oSegment.DataElement[4].Description + ' = ' + oSegment.DataElementValue[4,1]);   //SHIPTO NAME
                end;
             end
             else if sPartyEntity = 'BY' then begin  //Buyer address
                if sSegmentID = 'NAD' then begin
                   sValue := oSegment.DataElementValue[1,0];     // Party qualifier
                   sValue := oSegment.DataElementValue[2,1];     // Party identification
                   sValue := oSegment.DataElementValue[2,2];     // Code list qualifier
                   sValue := oSegment.DataElementValue[2,3];     // Code list responsible agency, coded
                   sValue := oSegment.DataElementValue[3,1];     // Name and address line
                   sValue := oSegment.DataElementValue[3,2];     // Name and address line
                   sValue := oSegment.DataElementValue[3,3];     // Name and address line
                   sValue := oSegment.DataElementValue[3,4];     // Name and address line
                   sValue := oSegment.DataElementValue[3,5];     // Name and address line
                   ListBox1.Items.Add(oSegment.DataElement[4].Description + ' = ' + oSegment.DataElementValue[4,1]);   //BUYER NAME
                end;
             end;
         end
         else if sLoopSection = 'NAD;RFF' then begin
             if sPartyEntity = 'RE' then begin  //Remit-to reference
                if sSegmentID = 'RFF' then begin
                   sValue := oSegment.DataElementValue[1,1];     // Reference qualifier
                   ListBox1.Items.Add(oSegment.DataElement[1].Description + ' = ' + oSegment.DataElementValue[1,2]);   //MANUFACTURER REFERENCE
                   sValue := oSegment.DataElementValue[1,3];     // Line number
                end;
             end
             else if sPartyEntity = 'ST' then begin  //Ship-to reference
                if sSegmentID = 'RFF' then begin
                   sValue := oSegment.DataElementValue[1,1];     // Reference qualifier
                   sValue := oSegment.DataElementValue[1,2];     // Reference number
                   sValue := oSegment.DataElementValue[1,3];     // Line number
                end;   //sSegmentID
             end
             else if sPartyEntity = 'BY' then begin  //Buyer reference
                if sSegmentID = 'RFF' then begin
                   sValue := oSegment.DataElementValue[1,1];     // Reference qualifier
                   sValue := oSegment.DataElementValue[1,2];     // Reference number
                   sValue := oSegment.DataElementValue[1,3];     // Line number
                end;   //sSegmentID

             end;
         end
         else if sLoopSection = 'NAD;CTA' then begin
             if sPartyEntity = 'RE' then begin  //Remit-to contact
                if sSegmentID = 'CTA' then begin
                   sValue := oSegment.DataElementValue[1,0];     // Contact function, coded
                   sValue := oSegment.DataElementValue[2,1];     // Department or employee identification
                   ListBox1.Items.Add(oSegment.DataElement[2].Description + ' = ' + oSegment.DataElementValue[2,2]);     // Department or employee
                end
                else if sSegmentID = 'COM' then begin
                   sValue := oSegment.DataElementValue[1,1];     // Communication number
                   sValue := oSegment.DataElementValue[1,2];     // Communication channel qualifier
                end;
             end
             else if sPartyEntity = 'ST' then begin  //Ship-to contact
                if sSegmentID = 'CTA' then begin
                   sValue := oSegment.DataElementValue[1,0];     // Contact function, coded
                   sValue := oSegment.DataElementValue[2,1];     // Department or employee identification
                   sValue := oSegment.DataElementValue[2,2];     // Department or employee
                end
                else if sSegmentID = 'COM' then begin
                   sValue := oSegment.DataElementValue[1,1];     // Communication number
                   sValue := oSegment.DataElementValue[1,2];     // Communication channel qualifier
                end;   //sSegmentID
             end
             else if sPartyEntity = 'BY' then begin  //Buyer contact
                if sSegmentID = 'CTA' then begin
                   sValue := oSegment.DataElementValue[1,0];     // Contact function, coded
                   sValue := oSegment.DataElementValue[2,1];     // Department or employee identification
                   sValue := oSegment.DataElementValue[2,2];     // Department or employee
                end
                else if sSegmentID = 'COM' then begin
                   sValue := oSegment.DataElementValue[1,1];     // Communication number
                   sValue := oSegment.DataElementValue[1,2];     // Communication channel qualifier
                end;   //sSegmentID
             end;
         end;  //sLoopSection
      end  //nArea = 1
      else if nArea = 2 then begin
         if sLoopSection = 'LIN' then begin
            if sSegmentID = 'LIN' then begin
               ListBox1.Items.Add(oSegment.DataElement[1].Description + ' = ' + oSegment.DataElementValue[1,0]);  //LINE NUMBER
               sValue := oSegment.DataElementValue[2,0];     // Action request/notification, coded
               ListBox1.Items.Add(oSegment.DataElement[3].Description + ' = ' + oSegment.DataElementValue[3,1]);  //BUYER PART NO
               sValue := oSegment.DataElementValue[3,2];     // Item number type, coded
               sValue := oSegment.DataElementValue[3,3];     // Code list qualifier
               sValue := oSegment.DataElementValue[3,4];     // Code list responsible agency, coded
            end
            else if sSegmentID = 'QTY' then begin
               sValue := oSegment.DataElementValue[1,1];     // Quantity qualifier
               ListBox1.Items.Add(oSegment.DataElement[1].Description + ' = ' + oSegment.DataElementValue[1,2]);  //QUANTITY
               ListBox1.Items.Add(oSegment.DataElement[1].Description + ' = ' + oSegment.DataElementValue[1,3]);  //MEASURE
            end;
         end
         else if sLoopSection = 'LIN;PRI' then begin
            if sSegmentID = 'PRI' then begin
               sValue := oSegment.DataElementValue[1,1];     // Price qualifier
               ListBox1.Items.Add(oSegment.DataElement[1].Description + ' = ' + oSegment.DataElementValue[1,2]);  //ITEM PRICE
            end;
         end;  //sLoopSection = 'LIN'
      end
      else if nArea = 3 then begin
         if sLoopSection = '' then begin
            if sSegmentID = 'UNS' then begin
               sValue := oSegment.DataElementValue[1,0];     // Section identification
            end;   //sSegmentID
         end
         else if sLoopSection = 'MOA' then begin
            if sSegmentID = 'MOA' then begin
               sValue := oSegment.DataElementValue[1,1];     // Monetary amount type qualifier
               ListBox1.Items.Add(oSegment.DataElement[1].Description + ' = ' + oSegment.DataElementValue[1,2]);  //TOTAL AMOUNT
               sValue := oSegment.DataElementValue[1,3];     // Currency, coded
               sValue := oSegment.DataElementValue[1,4];     // Currency qualifier
               sValue := oSegment.DataElementValue[1,5];     // Status, coded
            end;
         end
         else if sLoopSection = 'TAX' then begin
            if sSegmentID = 'TAX' then begin
               sValue := oSegment.DataElementValue[1,0];     // Duty/tax/fee function qualifier
               sValue := oSegment.DataElementValue[2,1];     // Duty/tax/fee type, coded
               sValue := oSegment.DataElementValue[2,2];     // Code list qualifier
               sValue := oSegment.DataElementValue[2,3];     // Code list responsible agency, coded
               sValue := oSegment.DataElementValue[2,4];     // Duty/tax/fee type
               sValue := oSegment.DataElementValue[3,1];     // Duty/tax/fee account identification
               sValue := oSegment.DataElementValue[3,2];     // Code list qualifier
               sValue := oSegment.DataElementValue[3,3];     // Code list responsible agency, coded
               sValue := oSegment.DataElementValue[4,0];     // Duty/tax/fee assessment basis
               sValue := oSegment.DataElementValue[5,1];     // Duty/tax/fee rate identification
               sValue := oSegment.DataElementValue[5,2];     // Code list qualifier
               sValue := oSegment.DataElementValue[5,3];     // Code list responsible agency, coded
               sValue := oSegment.DataElementValue[5,4];     // Duty/tax/fee rate
               sValue := oSegment.DataElementValue[5,5];     // Duty/tax/fee rate basis identification
               sValue := oSegment.DataElementValue[5,6];     // Code list qualifier
               sValue := oSegment.DataElementValue[5,7];     // Code list responsible agency, coded
               sValue := oSegment.DataElementValue[6,0];     // Duty/tax/fee category, coded
            end
            else if sSegmentID = 'MOA' then begin
               sValue := oSegment.DataElementValue[1,1];     // Monetary amount type qualifier
               ListBox1.Items.Add(oSegment.DataElement[1].Description + ' = ' + oSegment.DataElementValue[1,2]);  //TAX AMOUNT
               sValue := oSegment.DataElementValue[1,3];     // Currency, coded
               sValue := oSegment.DataElementValue[1,4];     // Currency qualifier
               sValue := oSegment.DataElementValue[1,5];     // Status, coded
            end;
         end;
      end;  //nArea

      //get next data segment
      oSegment := oSegment.Next as IediDataSegment;
   end;

   ShowMessage('Translate done');
   cmdTranslate.Enabled := true;

end;