📄 jcledisef.pas
字号:
{**************************************************************************************************}
{ }
{ Project JEDI Code Library (JCL) }
{ }
{ The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); }
{ you may not use this file except in compliance with the License. You may obtain a copy of the }
{ License at http://www.mozilla.org/MPL/ }
{ }
{ Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF }
{ ANY KIND, either express or implied. See the License for the specific language governing rights }
{ and limitations under the License. }
{ }
{ The Original Code is JclEDISEF.pas. }
{ }
{ The Initial Developer of the Original Code is Raymond Alexander. }
{ Portions created by Raymond Alexander are Copyright (C) Raymond Alexander. All rights reserved. }
{ }
{ Contributor(s): }
{ Raymond Alexander (rayspostbox3), Robert Marquardt, Robert Rossmair, Petr Vones }
{ }
{**************************************************************************************************}
{ }
{ EDI Standard Exchange Format (*.sef) File Parser Unit }
{ }
{ This unit is still in development }
{ }
{ Unit owner: Raymond Alexander }
{ Date created: July, 20, 2003 }
{ Additional Info: }
{ E-Mail at RaysDelphiBox3 att hotmail dott com }
{ For latest EDI specific demos see http://sourceforge.net/projects/edisdk }
{ See home page for latest news & events and online help. }
{ }
{**************************************************************************************************}
// $Id: JclEDISEF.pas,v 1.20 2005/03/08 16:10:07 marquardt Exp $
unit JclEDISEF;
{$I jcl.inc}
{$IFDEF SUPPORTS_WEAKPACKAGEUNIT}
{$WEAKPACKAGEUNIT ON}
{$ENDIF SUPPORTS_WEAKPACKAGEUNIT}
interface
uses
SysUtils, Classes, Contnrs,
JclEDI;
const
SectionTag_VER = '.VER';
SectionTag_INI = '.INI';
SectionTag_PRIVATE = '';
SectionTag_PUBLIC = '';
SectionTag_STD = '.STD';
SectionTag_SETS = '.SETS';
SectionTag_SEGS = '.SEGS';
SectionTag_COMS = '.COMS';
SectionTag_ELMS = '.ELMS';
SectionTag_CODES = '.CODES';
SectionTag_VALLISTS = '';
SectionTag_OBJVARS = '';
SectionTag_SEMREFS = '';
SectionTag_TEXT = '';
SectionTag_TEXTSETS = '.TEXT,SETS';
SectionTag_ = '';
// EDI SDK Specific Extensions
SectionTag_JCL_SETSEXT = '.SETSEXT';
SectionTag_JCL_SEGSEXT = '.SEGSEXT';
SectionTag_JCL_COMSEXT = '.COMSEXT';
SectionTag_JCL_ELMSEXT = '.ELMSEXT';
Value_UndefinedMaximum = MaxInt;
EDISEFUserAttributePeriod = '.';
EDISEFUserAttributeExclamationPoint = '!';
EDISEFUserAttributeDollarSign = '$';
EDISEFUserAttributeHyphen = '-';
EDISEFUserAttributeAmpersand = '&';
EDISEFUserAttributePeriodDesc = 'Not Used';
EDISEFUserAttributeExclamationPointDesc = 'Mandatory';
EDISEFUserAttributeDollarSignDesc = 'Recommended';
EDISEFUserAttributeHyphenDesc = 'Not Recommended';
EDISEFUserAttributeAmpersandDesc = 'Dependent';
EDISEFUserAttributeSet =
[EDISEFUserAttributePeriod, EDISEFUserAttributeExclamationPoint,
EDISEFUserAttributeDollarSign, EDISEFUserAttributeHyphen,
EDISEFUserAttributeAmpersand];
const
// EDI SEF Text,Sets Constants
SEFTextCR = '\r'; // carriage return
SEFTextLF = '\n'; // line feed
SEFTextCRLF = SEFTextCR + SEFTextLF;
// Example: Transaction Set:850
SEFTextSetsCode_Set0 = '0'; // Transaction Set or message title.
SEFTextSetsCode_Set1 = '1'; // Transaction Set functional group (X12).
SEFTextSetsCode_Set2 = '2'; // Transaction Set or message purpose.
SEFTextSetsCode_Set3 = '3'; // Level 1 note on transaction set or message.
SEFTextSetsCode_Set4 = '4'; // Level 2 note on transaction set or message.
SEFTextSetsCode_Set5 = '5'; // Level 3 note on transaction set or message. See * below for other levels of notes.
// Example: Transaction Set~segment ordinal number: 850~1
SEFTextSetsCode_Seg0 = '0'; // Segment reference notes that are part of the transaction set in X12.
SEFTextSetsCode_Seg1 = '1'; // Segment reference notes documented with the segment (like in VICS/UCS).
SEFTextSetsCode_Seg2 = '2'; // Segment reference comment documented with the transaction set.
SEFTextSetsCode_Seg3 = '3'; // Segment name.
SEFTextSetsCode_Seg4 = '4'; // Level 1 note on segment.
SEFTextSetsCode_Seg5 = '5'; // Level 2 note on segment.
SEFTextSetsCode_Seg6 = '6'; // Segment purpose.
SEFTextSetsCode_Seg7 = '7'; // Level 3 note on segment. See * below for other levels of notes.
// Example: Transaction Set~segment ordinal number~element or composite ordinal number: 850~1~4
SEFTextSetsCode_Elm0 = '0'; // Level 1 note on element or composite.
SEFTextSetsCode_Elm1 = '1'; // Level 2 note on element or composite.
SEFTextSetsCode_Elm2 = '2'; // Name of element or composite.
SEFTextSetsCode_Elm4 = '4'; // Level 3 note on element or composite. See * below for other levels of notes.
type
TEDISEFComsUserAttributes =
(caPeriod, caExclamationPoint, caDollarSign, caHyphen, caAmpersand);
TEDISEFObject = class(TEDIObject);
TEDISEFDataObject = class;
TEDISEFDataObjectGroup = class;
TEDISEFSubElement = class;
TEDISEFElement = class;
TEDISEFCompositeElement = class;
TEDISEFSegment = class;
TEDISEFLoop = class;
TEDISEFTable = class;
TEDISEFSet = class;
TEDISEFFile = class;
TEDISEFDataObjectListItem = class;
TEDISEFDataObjectList = class;
TEDISEFObjectParentType =
(sefNil, sefList, sefElement, sefCompositeElement, sefSegment);
// EDI SEF Data Object
TEDISEFDataObject = class(TEDISEFObject)
private
procedure SetId(const Value: string);
protected
FState: TEDIDataObjectDataState;
FId: string;
FData: string;
FLength: Integer;
FParent: TEDISEFDataObject;
FSEFFile: TEDISEFFile;
FErrorLog: TStrings;
FOwnerItemRef: TEDISEFDataObjectListItem;
function GetData: string;
procedure SetData(const Data: string);
procedure SetParent(const Value: TEDISEFDataObject); virtual;
property OwnerItemRef: TEDISEFDataObjectListItem read FOwnerItemRef write FOwnerItemRef;
public
constructor Create(Parent: TEDISEFDataObject); reintroduce;
destructor Destroy; override;
function Assemble: string; virtual; abstract;
procedure Disassemble; virtual; abstract;
procedure UpdateOwnerItemName;
{$IFDEF COMPILER6_UP} // Hide warnings in D5
function Clone(NewParent: TEDISEFDataObject): TEDISEFDataObject; virtual; abstract;
{$ELSE}
function Clone(NewParent: TEDISEFDataObject): TEDISEFDataObject; virtual;
{$ENDIF COMPILER6_UP}
published
property State: TEDIDataObjectDataState read FState;
property Id: string read FId write SetId;
property Data: string read GetData write SetData;
property DataLength: Integer read FLength;
property Parent: TEDISEFDataObject read FParent write SetParent;
property SEFFile: TEDISEFFile read FSEFFile write FSEFFile;
end;
TEDISEFDataObjectClass = class of TEDISEFDataObject;
// EDI SEF Data Object List Item
TEDISEFDataObjectListItem = class(TEDIObjectListItem)
private
function GetEDISEFDataObject: TEDISEFDataObject;
procedure SetEDISEFDataObject(const Value: TEDISEFDataObject);
public
procedure LinkToObject;
procedure UpdateName;
function NextItem: TEDISEFDataObjectListItem;
function PriorItem: TEDISEFDataObjectListItem;
published
property EDISEFDataObject: TEDISEFDataObject read GetEDISEFDataObject write SetEDISEFDataObject;
end;
// EDI SEF Data Object List
TEDISEFDataObjectList = class(TEDIObjectList)
private
function GetEDISEFDataObject(Index: Integer): TEDISEFDataObject;
procedure SetEDISEFDataObject(Index: Integer; const Value: TEDISEFDataObject);
public
function CreateListItem(PriorItem: TEDIObjectListItem;
EDIObject: TEDIObject = nil): TEDIObjectListItem; override;
function First(Index: Integer = 0): TEDISEFDataObjectListItem; reintroduce;
function Next: TEDISEFDataObjectListItem; reintroduce;
function Prior: TEDISEFDataObjectListItem; reintroduce;
function Last: TEDISEFDataObjectListItem; reintroduce;
function Add(EDISEFDataObject: TEDISEFDataObject;
Name: string = ''): TEDISEFDataObjectListItem; overload;
function Insert(EDISEFDataObject,
BeforeEDISEFDataObject: TEDISEFDataObject): TEDISEFDataObjectListItem; overload;
function FindItemByName(Name: string;
StartItem: TEDIObjectListItem = nil): TEDISEFDataObjectListItem; reintroduce;
function GetObjectByItemByName(Name: string): TEDISEFDataObject;
//
property EDISEFDataObject[Index: Integer]: TEDISEFDataObject read GetEDISEFDataObject
write SetEDISEFDataObject; default;
end;
// EDI SEF Data Object Group
TEDISEFDataObjectGroup = class(TEDISEFDataObject)
private
function GetEDISEFDataObject(Index: Integer): TEDISEFDataObject;
function GetCount: Integer;
protected
FEDISEFDataObjects: TEDISEFDataObjectList;
public
constructor Create(Parent: TEDISEFDataObject); reintroduce;
destructor Destroy; override;
property EDISEFDataObject[Index: Integer]: TEDISEFDataObject read GetEDISEFDataObject; default;
published
property EDISEFDataObjects: TEDISEFDataObjectList read FEDISEFDataObjects;
property EDISEFDataObjectCount: Integer read GetCount;
end;
// EDI SEF Repeating Pattern
TEDISEFRepeatingPattern = class(TEDISEFDataObjectGroup)
private
FBaseParent: TEDISEFDataObject;
FRepeatCount: Integer;
protected
procedure SetParent(const Value: TEDISEFDataObject); override;
public
constructor Create(Parent: TEDISEFDataObject); reintroduce;
destructor Destroy; override;
function Assemble: string; override;
procedure Disassemble; override;
function Clone(NewParent: TEDISEFDataObject): TEDISEFRepeatingPattern; reintroduce;
function AddRepeatingPattern: TEDISEFRepeatingPattern;
function AppendRepeatingPattern(
RepeatingPattern: TEDISEFRepeatingPattern): TEDISEFRepeatingPattern;
function ExtractRepeatingPattern(
RepeatingPattern: TEDISEFRepeatingPattern): TEDISEFRepeatingPattern;
procedure DeleteRepeatingPattern(
RepeatingPattern: TEDISEFRepeatingPattern);
function InsertRepeatingPattern(
BeforeObject: TEDISEFDataObject): TEDISEFRepeatingPattern; overload;
function InsertRepeatingPattern(RepeatingPattern: TEDISEFRepeatingPattern;
BeforeObject: TEDISEFDataObject): TEDISEFRepeatingPattern; overload;
published
property BaseParent: TEDISEFDataObject read FBaseParent;
property RepeatCount: Integer read FRepeatCount write FRepeatCount;
end;
// EDI SEF Text Objects
TEDISEFWhereType = (twUnknown, twSet, twSegment, twElementOrCompositeElement, twSubElement);
TEDISEFText = class(TEDIObject)
private
FWhereLocation: TStringList;
function GetText: string;
procedure SetText(const Value: string);
function GetDescription: string;
function GetWhereLocation: TStrings;
protected
FData: string;
FEDISEFWhereType: TEDISEFWhereType;
FWhere: string;
FWhat: string;
FText: string;
function GetData: string;
procedure SetData(const Value: string);
function Assemble: string; virtual;
procedure Disassemble; virtual;
public
constructor Create;
destructor Destroy; override;
published
property Data: string read GetData write SetData;
property WhereLocation: TStrings read GetWhereLocation;
property Where: string read FWhere;
property What: string read FWhat;
property Text: string read GetText write SetText;
property Description: string read GetDescription;
end;
TEDISEFTextSet = class(TEDISEFText)
private
FWhereSet: string;
FWhereSegment: Integer; // Ordinal
FWhereElement: Integer; // Ordinal
FWhereSubElement: Integer; // Ordinal
public
constructor Create;
destructor Destroy; override;
function Assemble: string; override;
procedure Disassemble; override;
end;
TEDISEFTextSets = class(TEDIObjectList)
public
function GetText(Code: string): string;
procedure SetText(EDISEFFile: TEDISEFFile; Location, Code, Text: string);
end;
// EDI SEF Element
TEDISEFElement = class(TEDISEFDataObject)
protected
FUserAttribute: string;
FOrdinal: Integer;
FOutOfSequenceOrdinal: Boolean;
FElementType: string;
FMinimumLength: Integer;
FMaximumLength: Integer;
FRequirementDesignator: string;
FRepeatCount: Integer;
FEDISEFTextSets: TEDISEFTextSets;
public
constructor Create(Parent: TEDISEFDataObject); reintroduce;
destructor Destroy; override;
function Assemble: string; override;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -