procedure TForm1.btnGenerateClick(Sender: TObject);
// THIS IS JUST AN EXAMPLE PROGRAM TO SHOW HOW TO GENERATE AN EDI X12 211 FILE 
// USING THE FRAMEWORK EDI COMPONENT IN DELPHI.

var
   oEdiDoc: IediDocument;
   oSchemas: IediSchemas;
   oInterchange: IediInterchange;
   oGroup: IediGroup;
   oTransactionset: IediTransactionset;
   oSegment: IediDataSegment;
 
begin
   // 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 GENERATE THE EDI FILE.
   oSchemas := oEdiDoc.GetSchemas as IediSchemas;
   oSchemas.EnableStandardReference := false;
 
   // ENABLES FORWARD WRITE, AND INCREASES BUFFER I/O TO IMPROVE PERFORMANCE
   oEdiDoc.CursorType := 2;
   oEdiDoc.Property_[1002] := 200;
 
   // SET TERMINATORS
   oEdiDoc.SegmentTerminator := '~{13:10}';
   oEdiDoc.ElementTerminator := '*';
   oEdiDoc.CompositeTerminator := '>';
 
   // LOADS SEF FILE
   oEdidoc.LoadSchema('211_003070.SEF',0);
 
   // CREATES THE ISA SEGMENT
   oInterchange := oEdidoc.CreateInterchange('X','003070') as IediInterchange;
   oSegment := oInterchange.GetDataSegmentHeader as IediDataSegment;
   oSegment.DataElementValue[1,0] := '00';     // Authorization Information Qualifier
   oSegment.DataElementValue[2,0] := '          ';     // Authorization Information
   oSegment.DataElementValue[3,0] := '00';     // Security Information Qualifier
   oSegment.DataElementValue[4,0] := '          ';     // Security Information
   oSegment.DataElementValue[5,0] := 'ZZ';     // Interchange ID Qualifier
   oSegment.DataElementValue[6,0] := 'AABB           ';     // Interchange Sender ID
   oSegment.DataElementValue[7,0] := '01';     // Interchange ID Qualifier
   oSegment.DataElementValue[8,0] := '112233445      ';     // Interchange Receiver ID
   oSegment.DataElementValue[9,0] := '080304';     // Interchange Date
   oSegment.DataElementValue[10,0] := '1116';     // Interchange Time
   oSegment.DataElementValue[11,0] := 'U';     // Interchange Control Standards Identifier
   oSegment.DataElementValue[12,0] := '00307';     // Interchange Control Version Number
   oSegment.DataElementValue[13,0] := '000017859';     // Interchange Control Number
   oSegment.DataElementValue[14,0] := '0';     // Acknowledgment Requested
   oSegment.DataElementValue[15,0] := 'P';     // Usage Indicator
   oSegment.DataElementValue[16,0] := '>';     // Component Element Separator
 
   // CREATES THE GS SEGMENT
   oGroup := oInterchange.CreateGroup('003070') as IediGroup;
   oSegment := oGroup.GetDataSegmentHeader as IediDataSegment;
   oSegment.DataElementValue[1,0] := 'BL';     // Functional Identifier Code
   oSegment.DataElementValue[2,0] := 'AABB';     // Application Sender's Code
   oSegment.DataElementValue[3,0] := '112233445';     // Application Receiver's Code
   oSegment.DataElementValue[4,0] := '080304';     // Date
   oSegment.DataElementValue[5,0] := '1116';     // Time
   oSegment.DataElementValue[6,0] := '1';     // Group Control Number
   oSegment.DataElementValue[7,0] := 'X';     // Responsible Agency Code
   oSegment.DataElementValue[8,0] := '003070';     // Version / Release / Industry Identifier Code
 
   // CREATES THE ST SEGMENT
   oTransactionset := oGroup.CreateTransactionset('211') as IediTransactionset;
   oSegment := oTransactionset.GetDataSegmentHeader as IediDataSegment;
   oSegment.DataElementValue[1,0] := '211';     // Transaction Set Identifier Code
   oSegment.DataElementValue[2,0] := '000010001';     // Transaction Set Control Number
 
   // BOL - BEGINNING SEGMENT FOR THE MOTOR CARRIER BILL OF LADING
   oSegment := oTransactionset.CreateDataSegment('BOL') as IediDataSegment;
   oSegment.DataElementValue[1,0] := 'SCAC';     // Standard Carrier Alpha Code
   oSegment.DataElementValue[2,0] := 'PP';     // Shipment Method of Payment
   oSegment.DataElementValue[3,0] := '12345';     // Shipment Identification Number
   oSegment.DataElementValue[4,0] := '990501';     // Date
   oSegment.DataElementValue[6,0] := '1231234561';     // Reference Identification
 
   // B2A - SET PURPOSE
   oSegment := oTransactionset.CreateDataSegment('B2A') as IediDataSegment;
   oSegment.DataElementValue[1,0] := '00';     // Transaction Set Purpose Code
 
   // MS2 - EQUIPMENT OR CONTAINER OWNER AND TYPE
   oSegment := oTransactionset.CreateDataSegment('MS2') as IediDataSegment;
   oSegment.DataElementValue[1,0] := 'SCAC';     // Standard Carrier Alpha Code
   oSegment.DataElementValue[2,0] := '123456';     // Equipment Number
 
   // N1 - NAME
   oSegment := oTransactionset.CreateDataSegment('N1\N1') as IediDataSegment;
   oSegment.DataElementValue[1,0] := 'SH';     // Entity Identifier Code
   oSegment.DataElementValue[2,0] := 'SHIPPER NAME';     // Name
   oSegment.DataElementValue[3,0] := '93';     // Identification Code Qualifier
   oSegment.DataElementValue[4,0] := '123456789';     // Identification Code
 
   // N3 - ADDRESS INFORMATION
   oSegment := oTransactionset.CreateDataSegment('N1\N3') as IediDataSegment;
   oSegment.DataElementValue[1,0] := '9999 SHIPPER STREET';     // Address Information
   oSegment.DataElementValue[2,0] := 'ADDITIONAL ADDRESS LINE';     // Address Information
 
   // N4 - GEOGRAPHIC LOCATION
   oSegment := oTransactionset.CreateDataSegment('N1\N4') as IediDataSegment;
   oSegment.DataElementValue[1,0] := 'SHIPPER CITY';     // City Name
   oSegment.DataElementValue[2,0] := 'ST';     // State or Province Code
   oSegment.DataElementValue[3,0] := '00000';     // Postal Code
 
   // N1 - NAME
   oSegment := oTransactionset.CreateDataSegment('N1(2)\N1') as IediDataSegment;
   oSegment.DataElementValue[1,0] := 'CN';     // Entity Identifier Code
   oSegment.DataElementValue[2,0] := 'CONSIGNEE NAME';     // Name
 
   // N3 - ADDRESS INFORMATION
   oSegment := oTransactionset.CreateDataSegment('N1(2)\N3') as IediDataSegment;
   oSegment.DataElementValue[1,0] := '9999 CONSIGNEE STREET';     // Address Information
   oSegment.DataElementValue[2,0] := 'ADDITIONAL ADDRESS LINE';     // Address Information
 
   // N4 - GEOGRAPHIC LOCATION
   oSegment := oTransactionset.CreateDataSegment('N1(2)\N4') as IediDataSegment;
   oSegment.DataElementValue[1,0] := 'CONSIGNEE CITY';     // City Name
   oSegment.DataElementValue[2,0] := 'ST';     // State or Province Code
   oSegment.DataElementValue[3,0] := '99999';     // Postal Code
 
   // G61 - CONTACT
   oSegment := oTransactionset.CreateDataSegment('N1(2)\G61') as IediDataSegment;
   oSegment.DataElementValue[1,0] := 'DC';     // Contact Function Code
   oSegment.DataElementValue[2,0] := 'DELIVERY CONTACT NAME';     // Name
   oSegment.DataElementValue[3,0] := 'TE';     // Communication Number Qualifier
   oSegment.DataElementValue[4,0] := '5559999999';     // Communication Number
 
   // AT1 - BILL OF LADING LINE ITEM NUMBER
   oSegment := oTransactionset.CreateDataSegment('AT1\AT1') as IediDataSegment;
   oSegment.DataElementValue[1,0] := '1';     // Lading Line Item Number
 
   // L11 - BUSINESS INSTRUCTIONS AND REFERENCE NUMBER
   oSegment := oTransactionset.CreateDataSegment('AT1\L11') as IediDataSegment;
   oSegment.DataElementValue[1,0] := '999';     // Reference Identification
   oSegment.DataElementValue[2,0] := 'AE';     // Reference Identification Qualifier
 
   // AT4 - BILL OF LADING DESCRIPTION
   oSegment := oTransactionset.CreateDataSegment('AT1\AT4') as IediDataSegment;
   oSegment.DataElementValue[1,0] := 'COMMODITY 1';     // Lading Description
 
   // AT2 - BILL OF LADING LINE ITEM DETAIL
   oSegment := oTransactionset.CreateDataSegment('AT1\AT2\AT2') as IediDataSegment;
   oSegment.DataElementValue[1,0] := '5';     // Lading Quantity
   oSegment.DataElementValue[2,0] := 'CTN';     // Packaging Form Code
   oSegment.DataElementValue[3,0] := 'N';     // Weight Qualifier
   oSegment.DataElementValue[4,0] := 'L';     // Weight Unit Code
   oSegment.DataElementValue[5,0] := '210';     // Weight
   oSegment.DataElementValue[9,0] := '999999-01';     // Commodity Code
 
   // MAN - MARKS AND NUMBERS
   oSegment := oTransactionset.CreateDataSegment('AT1\AT2\MAN') as IediDataSegment;
   oSegment.DataElementValue[1,0] := 'GM';     // Marks and Numbers Qualifier
   oSegment.DataElementValue[2,0] := '00000858050113093100';     // Marks and Numbers
 
   // MAN - MARKS AND NUMBERS
   oSegment := oTransactionset.CreateDataSegment('AT1\AT2\MAN(2)') as IediDataSegment;
   oSegment.DataElementValue[1,0] := 'GM';     // Marks and Numbers Qualifier
   oSegment.DataElementValue[2,0] := '00000858050113093101';     // Marks and Numbers
 
   // MAN - MARKS AND NUMBERS
   oSegment := oTransactionset.CreateDataSegment('AT1\AT2\MAN(3)') as IediDataSegment;
   oSegment.DataElementValue[1,0] := 'GM';     // Marks and Numbers Qualifier
   oSegment.DataElementValue[2,0] := '00000858050113093102';     // Marks and Numbers
 
   // MAN - MARKS AND NUMBERS
   oSegment := oTransactionset.CreateDataSegment('AT1\AT2\MAN(4)') as IediDataSegment;
   oSegment.DataElementValue[1,0] := 'GM';     // Marks and Numbers Qualifier
   oSegment.DataElementValue[2,0] := '00000858050113093103';     // Marks and Numbers
 
   // MAN - MARKS AND NUMBERS
   oSegment := oTransactionset.CreateDataSegment('AT1\AT2\MAN(5)') as IediDataSegment;
   oSegment.DataElementValue[1,0] := 'GM';     // Marks and Numbers Qualifier
   oSegment.DataElementValue[2,0] := '00000858050113093104';     // Marks and Numbers
 
   // SPO - SHIPMENT PURCHASE ORDER DETAIL
   oSegment := oTransactionset.CreateDataSegment('AT1\AT2\SPO') as IediDataSegment;
   oSegment.DataElementValue[1,0] := 'PO123567';     // Purchase Order Number
   oSegment.DataElementValue[2,0] := 'RF1144';     // Reference Identification
   oSegment.DataElementValue[3,0] := 'CP';     // Unit or Basis for Measurement Code
   oSegment.DataElementValue[4,0] := '12';     // Quantity
 
   // SPO - SHIPMENT PURCHASE ORDER DETAIL
   oSegment := oTransactionset.CreateDataSegment('AT1\AT2\SPO(2)') as IediDataSegment;
   oSegment.DataElementValue[1,0] := 'PO456789';     // Purchase Order Number
   oSegment.DataElementValue[2,0] := 'RF1144';     // Reference Identification
   oSegment.DataElementValue[3,0] := 'CP';     // Unit or Basis for Measurement Code
   oSegment.DataElementValue[4,0] := '15';     // Quantity
 
   // TRAILING SEGMENTS ARE AUTOMATICALLY CREATED

   // DISPLAY EDI STRING
   ShowMessage(oEdidoc.GetEdiString(0));

   // SAVE THE EDIDOC OBJECT INTO AN EDI FILE.
   oEdidoc.Save('211Output.X12',0);

   ShowMessage('Done');
 

end;