Article View: borland.public.delphi.language.objectpascal
Article #158Need advice: OOP approach to read EDI file
From: rodfaria
Date: Wed, 21 Jun 2006 14:17
Date: Wed, 21 Jun 2006 14:17
102 lines
3395 bytes
3395 bytes
Hi.
I`m creating a program that will convert one text file layout into
another
(for EDI between a bank and an ERP system).
Below are two approaches. Which one you experts think is the way to go
?
Line read (layout = record id, date, name, foo data, foo data)
---------
020060621John Doe 333444
Solution 1
----------
TBaseField = class
private
FValue:string;
public
constructor Create(line:string);virtual;abstract;
property Value:string read FValue;
end;
TFieldRecordId = class(TBaseField)
constructor Create(line:string);override;
end;
TFieldDate = class(TBaseField)
constructor Create(line:string);override;
end;
TFieldName = class(TBaseField)
constructor Create(line:string);override;
end;
//...one class for each Field, a lot of work!
constructor TFieldRecordId.Create(line: string);
begin
inherited;
FValue:=Copy(line,1,1);
end;
constructor TFieldDate.Create(line: string);
begin
inherited;
FValue:=Copy(line,2,8);
end;
constructor TFieldName.Create(line: string);
begin
inherited;
FValue:=Copy(line,10,10);
end;
Solution 2
----------
TSimpleField = class
private
FName:string;
FStart,FEnd:integer;
public
constructor Create(name:string;start_pos,end_pos:integer);
function Value(line:string):string;virtual;
end;
function TSimpleField.Value(line: string): string;
begin
Result:=Copy(line,FStart,FEnd-FStart+1);
end;
Using Solution 1
----------------
var
c1:TFieldRecordId;
c2:TFieldDate;
c3:TFieldName;
begin
c1:=TFieldRecordId.Create(edit1.text);
c2:=TFieldDate.Create(edit1.text);
c3:=TFieldName.Create(edit1.Text);
memo1.Lines.Add(c1.Value);
memo1.Lines.Add(c2.Value);
memo1.Lines.Add(c3.Value);
Using Solution 2
----------------
var
c1,c2,c3:TSimpleField;
begin
c1:=TSimpleField.Create('Record ID',1,1);
c2:=TSimpleField.Create('Date',2,9);
c3:=TSimpleField.Create('Name',10,19);
memo2.lines.add(c1.Value(edit1.text));
memo2.lines.add(c2.Value(edit1.text));
memo2.lines.add(c3.Value(edit1.Text));
...
Thanks,
Rod.
Technical Details
Message-ID:
<1150899439.644519.246230@c74g2000cwc.googlegroups.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!postnews.google.com!c74g2000cwc.googlegroups.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 109d30,836023d1078df195,start X-Google-Attributes: gid109d30,public X-Google-Language: ENGLISH,ASCII-7-bit Path: arc1-ca.pugleaf.net!g2news2.google.com!postnews.google.com!c74g2000cwc.googlegroups.com!not-for-mail From: "rodfaria" <rodolfo_faria@ig.com.br> Newsgroups: borland.public.delphi.language.objectpascal Subject: Need advice: OOP approach to read EDI file Date: 21 Jun 2006 07:17:19 -0700 Organization: http://groups.google.com Lines: 103 Message-ID: <1150899439.644519.246230@c74g2000cwc.googlegroups.com> NNTP-Posting-Host: 200.218.18.155 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1150899444 15690 127.0.0.1 (21 Jun 2006 14:17:24 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 21 Jun 2006 14:17:24 +0000 (UTC) User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727),gzip(gfe),gzip(gfe) X-HTTP-Via: 1.0 S01-MTZ-008 Complaints-To: groups-abuse@google.com Injection-Info: c74g2000cwc.googlegroups.com; posting-host=200.218.18.155; posting-account=R3Fk0w0AAAD01mYwLtK00LJdsi7DRQjp