Thema: Delphi Combining text files

Einzelnen Beitrag anzeigen

Benutzerbild von alcaeus
alcaeus

Registriert seit: 11. Aug 2003
Ort: München
6.537 Beiträge
 
#5

Re: Several questions

  Alt 2. Feb 2005, 12:49
Hello jcop,

since you have Delphi 2005 (or at least that's what your userprofile says ), the following method should work:

I'll show this for your first file, the Aircraft.txt. It works the same for all other files

Delphi-Quellcode:
type
  TAircraft=record
    sIndex, sDesc: String;
    iNumber: Integer;
  end;
//....

var
  i: Integer;
  SL1: TStringList;
  SL2: TStringList;
  Aircraft: array of TAirCraft;
begin
  SL1 := TStringList.Create(Self);
  SL2 := TStringList.Create(Self);
  try
    SL1.LoadFromFile('aircraft.txt');
//SL1 now contains all the lines stored in aircraft.txt
    SetLength(AirCraft, SL1.Count);
    for i := 0 to SL1.Count-1 do
    begin
      SL2.CommaText := SL1.Lines[i];
{SL2 now contains all the different entries that were separated by a comma. Note that the description can't contain commas}
      with Aircraft[i] do
      begin
        sIndex := SL2.Lines[0];
        iNumber := StrToIntDef(SL2.Lines[1], 0);
        sDesc := SL2.Lines[2];
      end;
    end;
  finally
    SL1.Free;
    SL2.Free;
  end;
end;
After that, the Aircraft-Array stores all your aircraft. Just return that array as a var parameter, and you should be set. For the other files it works equal, but if you have any problems, feel free to ask

Greetz
alcaeus
Andreas B.
Die Mutter der Dummen ist immer schwanger.
Ein Portal für Informatik-Studenten: www.infler.de
  Mit Zitat antworten Zitat