BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Need advice: OOP approach to read EDI file

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Language ObjectPascal
View previous topic :: View next topic  
Author Message
rodfaria
Guest





PostPosted: Wed Jun 21, 2006 7:17 pm    Post subject: Need advice: OOP approach to read EDI file Reply with quote



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,Cool;
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.
Back to top
Riki Wiki
Guest





PostPosted: Fri Jun 23, 2006 2:39 pm    Post subject: Re: Need advice: OOP approach to read EDI file Reply with quote



Hoi Rod

You need to repost your question on the Borland news server to make
everybody see it and possibly answer your question. Further, this news
group do not officially exist, the group to use is
b.p.d.language.delphi.general.

How to post to Delphi newsgroups:
<http://delphi.wikia.com/wiki/Delphi_Newsgroups>
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Language ObjectPascal All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.