X12Translator Component
Properties Methods Events Config Settings Errors
The X12Translator component converts X12 documents to XML and back, streamlining translation between formats.
Syntax
TedX12Translator
Remarks
The component will convert a document from the format specified by InputFormat to the format specified by OutputFormat. This allows for converting to XML from EDI and vice versa.
Before translating from EDI to XML it is recommended to load a schema using the LoadSchema method. This ensures additional information can be included in the XML or JSON document. If a schema is specified the XML will include types and descriptions as element attributes which are useful for interpreting the data.
After calling Translate the resulting output will contain the EDI or XML data as defined by OutputFormat.
Input and Output Properties
The component will determine the source and destination of the input and output based on which properties are set.
The order in which the input properties are checked is as follows:
When a valid source is found the search stops. The order in which the output properties are checked is as follows:- OutputFile
- OutputData: The output data is written to this property if no other destination is specified.
Property List
The following is the full list of the properties of the component with short descriptions. Click on the links for further details.
| DelimiterComponent | The delimiter separating components. |
| DelimiterElement | The delimiter separating elements. |
| DelimiterRepetition | The delimiter separating components. |
| DelimiterSegment | The delimiter separating segments. |
| FileWriteMode | Determines how the output file is opened for writing. |
| InputData | The EDI message, specified as a string. |
| InputFile | The file containing the EDI message. |
| InputFormat | The format of the input data. |
| OutputData | The translated EDI data. |
| OutputFile | The name of the file to write the translated EDI data to. |
| OutputFormat | The format of the output data. |
| SegmentSuffix | The suffix that is appended to the end of a segment. |
Method List
The following is the full list of the methods of the component with short descriptions. Click on the links for further details.
| Config | Sets or retrieves a configuration setting. |
| LoadSchema | Loads schema information from a file or string data. |
| Reset | Resets all properties to their default values. |
| Translate | Translates the specified data. |
Event List
The following is the full list of the events fired by the component with short descriptions. Click on the links for further details.
| Error | Fires when a parsing error occurs. |
| ResolveSchema | Fires to request schema information for a specific transaction set. |
| ValidateWarning | Fires to warn about validation errors. |
Config Settings
The following is a list of config settings for the component with short descriptions. Click on the links for further details.
| CloseStreamAfterTranslate | Whether to close the output stream after translation. |
| Encoding | The character encoding to use for the output X12 document. |
| UseDescriptions | Whether descriptions will be included in the output XML. |
DelimiterComponent Property (X12Translator Component)
The delimiter separating components.
Syntax
__property String DelimiterComponent = { read=FDelimiterComponent, write=FSetDelimiterComponent };
Default Value
":"
Remarks
The delimiter separating components.
In X12Reader, this type is used to hold the delimiters found when parsing the component, while in X12Writer the fields can be set to choose the delimiters that will be used when writing
This property is not available at design time.
Data Type
String
DelimiterElement Property (X12Translator Component)
The delimiter separating elements.
Syntax
__property String DelimiterElement = { read=FDelimiterElement, write=FSetDelimiterElement };
Default Value
"*"
Remarks
The delimiter separating elements.
In X12Reader, this type is used to hold the delimiters found when parsing the element, while in X12Writer the fields can be set to choose the delimiters that will be used when writing
This property is not available at design time.
Data Type
String
DelimiterRepetition Property (X12Translator Component)
The delimiter separating components.
Syntax
__property String DelimiterRepetition = { read=FDelimiterRepetition, write=FSetDelimiterRepetition };
Default Value
"^"
Remarks
The delimiter separating components.
In X12Reader, this type is used to hold the delimiters found when parsing the component, while in X12Writer the fields can be set to choose the delimiters that will be used when writing
This property is not available at design time.
Data Type
String
DelimiterSegment Property (X12Translator Component)
The delimiter separating segments.
Syntax
__property String DelimiterSegment = { read=FDelimiterSegment, write=FSetDelimiterSegment };
Default Value
"~"
Remarks
The delimiter separating segments.
In X12Reader, this type is used to hold the delimiters found when parsing the segment, while in X12Writer the fields can be set to choose the delimiters that will be used when writing
This property is not available at design time.
Data Type
String
FileWriteMode Property (X12Translator Component)
Determines how the output file is opened for writing.
Syntax
__property TedX12TranslatorFileWriteModes FileWriteMode = { read=FFileWriteMode, write=FSetFileWriteMode };
enum TedX12TranslatorFileWriteModes {
fwmCreate=0,
fwmOverwrite=1,
fwmAppend=2
};
Default Value
fwmCreate
Remarks
When OutputFile is set, this property determines how the file will be opened.
| fwmCreate | Creates a new file. If the file already exists, the translation will fail. |
| fwmOverwrite | Opens an existing file and overwrites its contents. If the file does not exist, a new file will be created. |
| fwmAppend | Opens an existing file and appends data to the end of the file. If the file does not exist, a new file will be created. |
This property is not available at design time.
Data Type
Integer
InputData Property (X12Translator Component)
The EDI message, specified as a string.
Syntax
__property String InputData = { read=FInputData, write=FSetInputData };
Default Value
""
Remarks
Set this property to specify the input EDI message as a string. The message can then be parsed with Parse.
This property is not available at design time.
Data Type
String
InputFile Property (X12Translator Component)
The file containing the EDI message.
Syntax
__property String InputFile = { read=FInputFile, write=FSetInputFile };
Default Value
""
Remarks
Set this property to specify the input EDI message as a file. The message can then be parsed with Parse.
If the file is not found or cannot be opened, an error will be returned.
Note: If both InputFile and InputData are set, InputData takes precedence.
This property is not available at design time.
Data Type
String
InputFormat Property (X12Translator Component)
The format of the input data.
Syntax
__property TedX12TranslatorInputFormats InputFormat = { read=FInputFormat, write=FSetInputFormat };
enum TedX12TranslatorInputFormats {
ifEDI=0,
ifXML=1
};
Default Value
ifEDI
Remarks
The value set here, along with OutputFormat, determines how the data is converted when Translate is called.
Possible values are:
- 0 (ifEDI)
- 1 (ifXML)
This property is not available at design time.
Data Type
Integer
OutputData Property (X12Translator Component)
The translated EDI data.
Syntax
__property String OutputData = { read=FOutputData, write=FSetOutputData };
Default Value
""
Remarks
This property will be populated with the translated data after calling Translate if OutputFile and SetOutputStream are not set.
This property is not available at design time.
Data Type
String
OutputFile Property (X12Translator Component)
The name of the file to write the translated EDI data to.
Syntax
__property String OutputFile = { read=FOutputFile, write=FSetOutputFile };
Default Value
""
Remarks
This file specified by this property will be populated with the output after calling Translate if SetOutputStream is not set.
If a file with the specified name already exists Translate will fail unless FileWriteMode is set to "fwmOverwrite" or "fwmAppend".
This property is not available at design time.
Data Type
String
OutputFormat Property (X12Translator Component)
The format of the output data.
Syntax
__property TedX12TranslatorOutputFormats OutputFormat = { read=FOutputFormat, write=FSetOutputFormat };
enum TedX12TranslatorOutputFormats {
ofEDI=0,
ofXML=1
};
Default Value
ofEDI
Remarks
The value set here, along with InputFormat, determines how the data is converted when Translate is called.
Possible values are:
- 0 (ofEDI)
- 1 (ofXML)
This property is not available at design time.
Data Type
Integer
SegmentSuffix Property (X12Translator Component)
The suffix that is appended to the end of a segment.
Syntax
__property TedX12TranslatorSegmentSuffixes SegmentSuffix = { read=FSegmentSuffix, write=FSetSegmentSuffix };
enum TedX12TranslatorSegmentSuffixes {
ssNone=0,
ssCR=1,
ssLF=2,
ssCRLF=3
};
Default Value
ssCRLF
Remarks
This property determines the suffix that is appended to the end of a segment.
Possible values are:
| ssNone (0) | No suffix is appended to the segment. |
| ssCR (1) | A carriage return (ASCII 13) is appended to the segment. |
| ssLF (2) | A line feed (ASCII 10) is appended to the segment. |
| ssCRLF (3) | A carriage return followed by a line feed (ASCII 13 and 10) is appended to the segment. This is the default value. |
This property is not available at design time.
Data Type
Integer
Config Method (X12Translator Component)
Sets or retrieves a configuration setting.
Syntax
String __fastcall Config(String ConfigurationString);
Remarks
Config is a generic method available in every component. It is used to set and retrieve configuration settings for the component.
These settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the component, access to these internal properties is provided through the Config method.
To set a configuration setting named PROPERTY, you must call Config("PROPERTY=VALUE"), where VALUE is the value of the setting expressed as a string. For boolean values, use the strings "True", "False", "0", "1", "Yes", or "No" (case does not matter).
To read (query) the value of a configuration setting, you must call Config("PROPERTY"). The value will be returned as a string.
LoadSchema Method (X12Translator Component)
Loads schema information from a file or string data.
Syntax
void __fastcall LoadSchema(String fileOrData, String messagename);
Remarks
This method loads schema information for use when parsing, validating, and translating messages.
The FileOrData parameter can be set to the path of a file containing schema data, or can be set to the contents of a schema file directly.
MessageName can be set to the name of a specific message to load only the specified message's schema information. If left empty or set to "*", the entire schema will be loaded.
Reset Method (X12Translator Component)
Resets all properties to their default values.
Syntax
void __fastcall Reset();
Remarks
This method resets all properties of the component to their default values as specified in the property definitions.
Translate Method (X12Translator Component)
Translates the specified data.
Syntax
void __fastcall Translate();
Remarks
This method translates the specified data.
Error Event (X12Translator Component)
Fires when a parsing error occurs.
Syntax
typedef struct {
int ErrorCode;
String Description;
} TedX12TranslatorErrorEventParams;
typedef void __fastcall (__closure *TedX12TranslatorErrorEvent)(System::TObject* Sender, TedX12TranslatorErrorEventParams *e);
__property TedX12TranslatorErrorEvent OnError = { read=FOnError, write=FOnError };
Remarks
This event fires when the component encounters a parsing error while processing a document.
ResolveSchema Event (X12Translator Component)
Fires to request schema information for a specific transaction set.
Syntax
typedef struct {
String VersionNumber;
String TransactionSetIDCode;
} TedX12TranslatorResolveSchemaEventParams;
typedef void __fastcall (__closure *TedX12TranslatorResolveSchemaEvent)(System::TObject* Sender, TedX12TranslatorResolveSchemaEventParams *e);
__property TedX12TranslatorResolveSchemaEvent OnResolveSchema = { read=FOnResolveSchema, write=FOnResolveSchema };
Remarks
LoadSchema can be called from within this event to load the schema information for the specified transaction set.
ValidateWarning Event (X12Translator Component)
Fires to warn about validation errors.
Syntax
typedef struct {
__int64 Position;
int Line;
int Column;
String ErrorCode;
String ErrorMessage;
int ErrorType;
} TedX12TranslatorValidateWarningEventParams;
typedef void __fastcall (__closure *TedX12TranslatorValidateWarningEvent)(System::TObject* Sender, TedX12TranslatorValidateWarningEventParams *e);
__property TedX12TranslatorValidateWarningEvent OnValidateWarning = { read=FOnValidateWarning, write=FOnValidateWarning };
Remarks
When the component encounters a non-blocking error while validating a document, this event fires with information about the error.
Config Settings (X12Translator Component)
The component accepts one or more of the following configuration settings. Configuration settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the component, access to these internal properties is provided through the Config method.X12Translator Config Settings
Trappable Errors (X12Translator Component)
X12Translator Errors
| 202 | Invalid argument. |
| 304 | Cannot write to file. |
| 1003 | Could not find the selected schema in the chosen file. |
| 1099 | Encountered an unexpected segment tag. |
| 1100 | Attempted to perform an action while the component was busy, or close an incomplete interchange. |
| 1044 | Tried to load an invalid schema file. |
| 1203 | Encountered an error while validating the UNA segment. |