AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Combining text files

Ein Thema von jcop · begonnen am 2. Feb 2005 · letzter Beitrag vom 3. Feb 2005
Antwort Antwort
Seite 1 von 2  1 2      
jcop

Registriert seit: 16. Dez 2004
9 Beiträge
 
Delphi 2005 Personal
 
#1

Combining text files

  Alt 2. Feb 2005, 13:02
Hello all,

I have a few questions, please note that I don't want a solution so i'm not trying to get you guys to create this for me, just point me in the right directions. Sorry that I ask these in English, but I cannot write German very well, but I can understand it perfect.

Problem 1.

I have 3 text files.

- Aircaft.txt
- Airports.txt
- flightplans.txt

The Aircraft.txt has following data.

AC#1,200,"Beech Baron 58"
AC#2,315,"Beech King Air 350"
AC#3,477,"Boeing 737-400"
etc....

Airports.txt contains this data

EDEB,N51* 7.72',E10* 37.25',646
EDEH,N49* 20.66',E8* 29.23',305
EDEL,N49* 54.47',E7* 54.43',292
EDEM,N51* 3.74',E9* 25.28',1312

Flightplans.txt has this data

AC#1,OO-ONJ,99%,WEEK,IFR,6/04:00:00,6/04:39:54,260,F,050,EDEB,6/07:00:00,6/07:39:54,260,F,051,EDEM

You probably guest this already, how can I combine these in Delphi.

The result must be a file (stringgrid?) showing this.

Type = Beech Baron 58
Departure = EDEM
Destination = EDEB
Dep Time=
Arr Time=
etc...

I'm able to import each of these files, but don't know how to start to combine them to check and change the AC#1 to the aircraft name.

Thanks in advance.
Johan
  Mit Zitat antworten Zitat
Benutzerbild von alcaeus
alcaeus

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

Re: Several questions

  Alt 2. Feb 2005, 13:05
Hi jcop,

forum rules say that you should ask only one question per topic. Therefore, please ask how to read the data in one topic, and the question about displaying the planes in a different topic. Otherwise we'll just have a huge mess in this topic.

Thanks for understanding

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

Registriert seit: 26. Nov 2003
Ort: Berlin
343 Beiträge
 
Delphi 2006 Professional
 
#3

Re: Several questions

  Alt 2. Feb 2005, 13:32
I try to answer in english ^^

1.) You must load your file into a stream or Memo Component

Exp.: Memo1.Lines.LoadFromFile('c:\Airplane.txt'); 2.) I would create an Record for the current "Flightplan"

Exp.:

Delphi-Quellcode:
type FPlan = record
    FAirCraft : String;
    FAirPort : String;
    FDate : String;
    FWeek : String;
  end;
3.) You need to fill this record with the current Flightplan. To do this I would seperate the "Line" through the comma ^^

Exp.:

Delphi-Quellcode:
type FPlan = record
    FAirCraft : String;
    FAirPort : String;
    FDate : String;
    FWeek : String;
  end;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
  var CurLine : String;
      CurComma : Byte;
      CurFlight : FPlan;
begin
  // load to memo (or stringlist / stream)
  Memo1.Lines.LoadFromFile('c:\Airplane.txt');

  // get the first line from the txt file (0 = first)
  // AC#1,OO-ONJ,99%,WEEK,IFR,6/04:00:00,6/04:39:54,260,F,050,EDEB,6/07:00:00,6/07:39:54,260,F,051,EDEM
  if Memo1.Lines.Count > 0 then
    CurLine := Memo1.Lines[0];

  // now find the next comma
  if Length(CurLine) > 0 then
    CurComma := Pos(CurLine, ',');

  // copy the text until the comma
  CurFlight.FAirCraft := Copy(CurLine, 0, CurComma - 1);

  // not cut the first entry from the line
  CurLine := Copy(CurLine, CurComma, Length(CurLine) - CurComma);

  // And now repeat that und you geht the OO-ONJ .. 99% .. WEEK

end;
However, that should be a possibility to combine these files...

///Added:

When you want to export something you would recommend to use 'IniFiles'

Delphi-Quellcode:
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, IniFiles;

var
  CurPlan : FPlan;

implementation

procedure TForm1.Button1Click(Sender: TObject);
  var ini :TIniFile;
begin
  ini := TIniFile.Create('c:\export.txt');
  ini.WriteString('CurFlight', 'Aircraft', CurPlan.FAirCraft;
  ini.WriteString('CurFlight', 'AirPort', CurPlan.FAirPort;
  //........
  ini.Free;
end;
Christian Reber
  Mit Zitat antworten Zitat
Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#4

Re: Several questions

  Alt 2. Feb 2005, 13:36
I'd preferr ExplodeExplode with dynamic arrays. Once you have your data in that array you can do what you want with it. Maybe even a dynamic array of
Delphi-Quellcode:
TAiroplane = record
  Name: String;
  Dest: String;
  ..: ..;
end;
wouldn't be such a bad idea.
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat
Benutzerbild von alcaeus
alcaeus

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

Re: Several questions

  Alt 2. Feb 2005, 13: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
Delphi_Fanatic

Registriert seit: 24. Mär 2004
201 Beiträge
 
#6

Re: Several questions

  Alt 2. Feb 2005, 14:08
( Why don't you use a Database, transfer all the data of the text-files to the tables of
the database ? )
  Mit Zitat antworten Zitat
Kernel32.DLL
(Gast)

n/a Beiträge
 
#7

Re: Several questions

  Alt 2. Feb 2005, 20:46
Zitat von Delphi_Fanatic:
( Why don't you use a Database, transfer all the data of the text-files to the tables of
the database ? )
It might be possible that he wants to use the DATA with the MS Flight Simulator, couldn't it?
  Mit Zitat antworten Zitat
moritz

Registriert seit: 18. Apr 2003
1.037 Beiträge
 
#8

Re: 1 question

  Alt 2. Feb 2005, 20:57
An alternetive solution XML-Files could be. An other way is to use the split-function presented on my webpage or an alternetive split-function (You can find them also in the Code-Library on this page). The splite-function of mine was written to make parsing of CVS-Files much easier.
"Optimistisch ist diejenige Weltanschauung, die das Sein höher als das Nichts stellt und so die Welt und das Leben als etwas an sich Wertvolles bejaht."
Albert Schweitzer
  Mit Zitat antworten Zitat
Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#9

Re: 1 question

  Alt 2. Feb 2005, 21:02
Would you please choose a meaningful and specific subject header? "1 questions" says nothing about problem / question. Just click the "edit"-button in your first posting.
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat
jcop

Registriert seit: 16. Dez 2004
9 Beiträge
 
Delphi 2005 Personal
 
#10

Re: Combining text files

  Alt 3. Feb 2005, 08:38
Thanks for all the input and my apoligies to all readers concerning the double post and the title not being specific enough.

to Kernel32.dll, yes I want to recreate a traffic AI program for MS flight simulator.

to Delphi_fanatic, I don't think it's possible to place these files into a database since the length of the flightlans.txt can vary, meaning you can have your flight start to fly to EDDM then back to EBBR. But you can also have a departing flight to EDDM - EBBR then to GCTS to EBBR. As you can see the destination can vary in destinations the aircraft is flying in on line. Each end of a line stops with ha hard return.

to alcaeus, I will try your answer and inform you about the result. This also applies for the answer from Christian.

Again thanks for all your aswers.

regards,
Johan
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 1 von 2  1 2      


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 03:25 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz