🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.delphi.language.objectpascal
2 messages
2 total messages Started by rodfaria Wed, 21 Jun 2006 14:17
Need advice: OOP approach to read EDI file
#158
Author: rodfaria
Date: Wed, 21 Jun 2006 14:17
102 lines
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.
Re: Need advice: OOP approach to read EDI file
#159
Author: Riki Wiki
Date: Fri, 23 Jun 2006 09:39
9 lines
1224 bytes
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>
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads