![]() |
Combining text files
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 |
Re: Several questions
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 |
Re: Several questions
I try to answer in english ^^
1.) You must load your file into a stream or Memo Component Exp.:
Delphi-Quellcode:
2.) I would create an Record for the current "Flightplan"
Memo1.Lines.LoadFromFile('c:\Airplane.txt');
Exp.:
Delphi-Quellcode:
3.) You need to fill this record with the current Flightplan. To do this I would seperate the "Line" through the comma ^^
type FPlan = record
FAirCraft : String; FAirPort : String; FDate : String; FWeek : String; end; Exp.:
Delphi-Quellcode:
However, that should be a possibility to combine these files...
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; ///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; |
Re: Several questions
I'd preferr
![]()
Delphi-Quellcode:
wouldn't be such a bad idea.
TAiroplane = record
Name: String; Dest: String; ..: ..; end; |
Re: Several questions
Hello jcop,
since you have Delphi 2005 (or at least that's what your userprofile says :zwinker:), 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:
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 :)
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; Greetz alcaeus |
Re: Several questions
( Why don't you use a Database, transfer all the data of the text-files to the tables of
the database ? ) |
Re: Several questions
Zitat:
|
Re: 1 question
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.
|
Re: 1 question
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.
|
Re: Combining text files
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 |
Alle Zeitangaben in WEZ +1. Es ist jetzt 04:01 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz