unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
StrUtils, StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
btnBuild: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
Edit6: TEdit;
Edit7: TEdit;
ListBox1: TListBox;
ListBox2: TListBox;
ListBox3: TListBox;
procedure btnBuildClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
function LoadDataFromFile(const AFileName: String): Boolean;
function GetCityCountry(ARCD : String) : String;
Procedure AddCity(ACity : String);
Procedure AddCountry(ACountry : String);
private
public
end;
Const
CFILENAME = 'C:\UserFiles\Apt.txt';
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
Var i : Integer = -1;
Found : Boolean = False;
begin
ListBox1.Clear;
ListBox2.Clear;
ListBox3.Clear;
end;
procedure TForm1.btnBuildClick(Sender: TObject);
begin
LoadDataFromFile(CFILENAME);
end;
function TForm1.LoadDataFromFile(const AFileName: String): Boolean;
var
DataFile : TextFile;
LineIn : String = '';
RCDCity : String[45]= '';
RCDCountry : String[45] = '';
RCD : String = '';
iApt : String = '';
RCDCTR : Integer;
FmtLine : String[185];
LNDCTR : Integer = -1;
SEACTR : Integer = -1;
HELICTR : Integer = -1;
nRCDCTR : String[5];
CityCtr : Integer = -1;
CityFound : Boolean = False;
CountryFound : Boolean = False;
begin
// Listbox1.Clear;
Result := True;
LNDCTR := 0;
SEACTR := 0;
HELICTR := 0;
RCDCTR := 0;
CityCtr := 0;
AssignFile(DataFile, AFileName);
try
Reset(DataFile);
while not eof(DataFile) do begin
Readln(DataFile, LineIn);
RCD := Copy2Space(LineIn);
Inc(RCDCTR);
Edit1.Text := IntToStr(RCDCTR);
iApt := ExtractWord(5, LineIn, [' ']);
Case RCD of
'1' : begin
nRCDCTR := IntToStr(RCDCTR);
FmtLine := iApt + ' ' + nRCDCTR;
ListBox1.Items.Add(FMTLine);
Inc(LNDCTR);
Edit2.Text := IntToStr(LNDCTR);
Continue;
end;
'16' : Begin
nRCDCTR := IntToStr(RCDCTR);
FmtLine := iApt + ' ' + nRCDCTR;
ListBox1.Items.Add(FMTLine);
Inc(SEACTR);
Edit3.Text := IntToStr(SEACTR);
Continue;
end;
'17' : begin
nRCDCTR := IntToStr(RCDCTR);
FmtLine := iApt + ' ' + nRCDCTR;
ListBox1.Items.Add(FMTLine);
Inc(HELICTR);
Edit4.Text := IntToStr(HELICTR);
Continue;
end;
'1302' : begin
CityFound := IsWordPresent('city', LineIn, [' ']);
if CityFound then begin RCDCity := GetCityCountry(LineIn); end;
if CityFound then begin AddCity(RCDCity); end;
CountryFound := IsWordPresent('country', LineIn, [' ']);
if CountryFound then begin RCDCountry := GetCityCountry(LineIn); end;
if CountryFound then begin AddCountry(RCDCountry); end;
FmtLine := iApt + ' ' + nRCDCTR;
Inc(HELICTR);
Edit4.Text := IntToStr(HELICTR);
Continue;
end;
end;
Application.ProcessMessages;
end;
CloseFile(DataFile);
except
Result := False;
end;
end;
procedure AddAirport(AAirport : String);
Var i : Integer = -1;
Item : String = '';
begin
Item := AAirport;
if AAirport.IsEmpty then begin exit; end;
Item := Trim(AAirport);
i := ListBox1.Items.Indexof(Item); // unit1.pas(157,10) Error: Identifier not found "ListBox1"
if i > -1 then begin exit; end;
Listbox1.Items.Add(Item);
end;
Procedure TForm1.AddCity(ACity : String);
Var i : Integer = -1;
Found : Boolean = False;
Item : String = '';
begin
Item := ACity;
i := Listbox2.Items.Indexof(Item);
if i > -1 then begin exit; end;
ListBox2.Items.Add(Item);
i := Listbox2.Items.Count;
Edit5.Text := IntToStr(i);
end;
Procedure TForm1.AddCountry(ACountry : String);
Var i : Integer = -1;
Found : Boolean = False;
Item : String = '';
begin
Item := ACountry;
i := Listbox3.Items.Indexof(Item);
if i > -1 then begin exit; end;
ListBox3.Items.Add(Item);
i := Listbox3.Items.Count;
Edit6.Text := IntToStr(i);
end;
function TForm1.GetCityCountry(ARCD : String) : String;
var i : Integer = -1;
Item : String = '';
Bit1 : String = '';
begin
Item := ARCD;
Bit1 := Copy2SpaceDel(Item);
Item := Trim(Item);
Bit1 := Copy2SpaceDel(Item);
Item := Trim(Item);
Result := Item;
end;
end.