Autor Beitrag
jcop
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27

WinXP, Vista
Delphi 2009, Vb.NET
BeitragVerfasst: Mo 28.09.09 09:20 
Hello,

Can someone please help me with following code.

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
procedure TSceneryListFrame.Button2Click(Sender: TObject);
var
  AcList : TStringList;
  i: Integer;
  line: string;
  IcaoAirlinesCode: PIcaoAirlinesCode;
  CSVFile: textfile;


  begin
    new(IcaoAirlinesCode);
    filepath := 'c:\IcaoAcCode.csv';
    AcList := Tstringlist.Create;
    try
      //AcList.LoadFromFile(filepath);
      Assignfile(CSVFile, filepath);
      Reset(CSVFile, filepath);
        while not EOF(CSVFile) do
        begin
          Readln(CSVFile, line);
          AcList.Delimiter := ',';
          AcList.DelimitedText := line;
          IcaoAirlinesCode.FName := AcList.Strings[0];
          IcaoAirlinesCode.CallSign := aclist.Strings[1];
          IcaoAirlinesCode.Icao := AcList.Strings[2];


          //cmb_Fullname.Assign := AcList.Strings[0];
          //cmb_Name.Items := IcaoAirlinesCode.CallSign;
          //cmb_ICAO.Items := aclist.Strings[2];
        end;
    finally

      CloseFile(CSVFile);
    end;

  end;


I want the acList.strings[0], [1], [2] to be added in the specific combobox, so whenever user clicks on the cmb_Fullname, the cmb_Name and cmb_ICAO will show the relevant items from the comma separated file.

Below is a piece of the file
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
"135 Airways","GENERAL","GNL",
"1Time Airline",,"1T_",
"223rd Flight Unit State Airline","CHKALOVSK-AVIA","CHD",
"224th Flight Unit","Cargo Unit","TTF",
"32 (TR) Squadron RAF Northolt","NORTHOLT","NOH",
"34 Squadron Royal Australian Air Force",,"EVY",
"40-Mile Air","MILE-AIR","MLA",
"611897 Alberta","DONUT","THD",
"84 Squadron RAF Akrotiri","Grifter","AKG",


Moderiert von user profile iconNarses: Überflüssige Zeilenumbrüche/Leerzeilen entfernt.
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 28.09.09 09:27 
Moin!

Zeig doch bitte noch mal, was das hier ist:
user profile iconjcop hat folgendes geschrieben Zum zitierten Posting springen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure TSceneryListFrame.Button2Click(Sender: TObject);
var
  AcList : TStringList;
  i: Integer;
  line: string;
  IcaoAirlinesCode: PIcaoAirlinesCode;
  CSVFile: textfile;
Dann würde ich dir hiermit mal einen objektorientierten Ansatz zeigen wollen. Das mit den records auf dem Heap ist doch etwas lästig, auf die Dauer. :?

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
jcop Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27

WinXP, Vista
Delphi 2009, Vb.NET
BeitragVerfasst: Mo 28.09.09 09:33 
Hi,

I taught of using a record to store the info since at the end I want to combine the 3 comboboxes. Below is the declarartion.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
type
  PIcaoAirlinesCode = ^TIcaoAirlinesCode;
  TIcaoAirlinesCode = record
    FName: String;
    CallSign: String;
    Icao: String;
  end;
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 28.09.09 10:25 
Moin!

user profile iconjcop hat folgendes geschrieben Zum zitierten Posting springen:
I taught of using a record to store the info since at the end I want to combine the 3 comboboxes.
OK, noch eine Frage, dann geht´s los (ist aber für das Konzept wichtig): Sind die Daten, die du in den drei ComboBoxen ablegen willst, eher als statisch zu betrachten (für eine Programmsitzung) oder sollen die verändert werden? Weiterhin: spricht was gegen ein TListView im Style lvReport? ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
jcop Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27

WinXP, Vista
Delphi 2009, Vb.NET
BeitragVerfasst: Mo 28.09.09 11:02 
Moderiert von user profile iconNarses: Komplett-Zitat des letzten Beitrags entfernt.

The values in the comboboxes should not depend from the CSV file only, so if the items in the list don't exist in the ac description file the user must be able to add these to the list, but I want to create a extra button for this which will load the complete CSV file in another form so I/user can add or change items.

regards and thanks for the assist.
Johan
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 28.09.09 11:49 
Moin!

Dann schau doch mal, ob du damit weiter kommst: ;)
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
procedure TForm1.Button1Click(Sender: TObject);
  var
    CSV, Line: TStringList;
    i: Integer;
    ListItem: TListItem;
begin
  if OpenDialog1.Execute then begin
    CSV := TStringList.Create;
    Line := TStringList.Create;
    try
      try
        CSV.LoadFromFile(OpenDialog1.FileName);
      except
        CSV.Clear;
        MessageDlg('Fehler beim Laden der Datei!'#13+Exception(ExceptObject).Message,mtError,[mbCancel],0);
      end;
      for i := 0 to CSV.Count-1 do begin
        Line.CommaText := CSV.Strings[i];
        if (Line.Count >= 3then begin
          ListItem := ListView1.Items.Add;
          ListItem.Caption := Line.Strings[0];
          ListItem.SubItems.Add(Line.Strings[1]);
          ListItem.SubItems.Add(Line.Strings[2]);
        end;
      end;
    finally
      Line.Free;
      CSV.Free;
    end;
  end;
end;
Und hier noch das ListView-Objekt:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
  object ListView1: TListView
    Left = 16
    Top = 16
    Width = 593
    Height = 193
    Columns = <
      item
        Caption = 'Name'
      end
      item
        Caption = 'CallSign'
      end
      item
        Caption = 'ICAO'
      end>
    GridLines = True
    HideSelection = False
    ReadOnly = True
    RowSelect = True
    TabOrder = 0
    ViewStyle = vsReport
  end
Mit Alt+F12 bei aktivem Formular in die DFM-Text-Ansicht wechseln und diesen Code dort einfügen, dann hast du das ListView auf der Form. Nochmal Alt+F12, dann hast du wieder die Formularansicht. :idea:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
jcop Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27

WinXP, Vista
Delphi 2009, Vb.NET
BeitragVerfasst: Mo 28.09.09 12:49 
Thanks now I'm able to load the 3 comboboxes, but I think I haven't explained my question in a correct way.

This CSV file holds 3 items which are related to each other. So when the user clicks on the combobox holding the fullname (the first string inside the CSV) then the other two comboboxes should show the
2nd and 3rd string automatically. That's also the reason I was thinking of putting the complete file
in a record. Correct me if this isn't the right way to do this in Delphi.

In VB2008 I've done this by creating a a database type

ausblenden volle Höhe Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
reader = New StreamReader((Application.StartupPath & "\ICAOACFTNAMES.CSV"))
        index = 0
        table = New DataTable("ICAOACFTNAMES")
        dataSource.Tables.Add(table)

        column3 = New DataColumn
        column3.DataType = System.Type.GetType("System.String")
        column3.AllowDBNull = True
        column3.Caption = ""
        column3.ColumnName = ""
        table.Columns.Add(column3)

        column3 = New DataColumn
        column3.DataType = Type.GetType("System.String")
        column3.AllowDBNull = False
        column3.Caption = "Airline"
        column3.ColumnName = "Airline"
        table.Columns.Add(column3)

        column3 = New DataColumn
        column3.DataType = System.Type.GetType("System.String")
        column3.AllowDBNull = False
        column3.Caption = "ATC_Airline"
        column3.ColumnName = "ATC_Airline"
        table.Columns.Add(column3)

        column3 = New DataColumn
        column3.DataType = System.Type.GetType("System.String")
        column3.AllowDBNull = False
        column3.Caption = "Parking Code"
        column3.ColumnName = "Parking Code"
        table.Columns.Add(column3)

 'Prepare the comboboxes for parkingcodes
        Me.AircraftView.kcmb_ATC_Parking_Codes.Sorted = False
        Me.AircraftView.kcmb_ATC_Parking_Codes_Full.Sorted = False
        Me.AircraftView.kcmb_ATC_Parking_Codes.BeginUpdate()
        Me.AircraftView.kcmb_ATC_Parking_Codes_Full.BeginUpdate()
        Me.AircraftView.kcmb_ATC_Parking_Codes.Items.Clear()
        Me.AircraftView.kcmb_ATC_Parking_Codes_Full.Items.Clear()

If (Not str.StartsWith(";") And (str.Length <> 0)) Then
                Dim strarray2 As String() = str.Split(New Char() {","c})
                Me.ATC_Airline(index).Parkingcode1 = strarray2(5)
                Me.ATC_Airline(index).Parkingcode2 = strarray2(4)
                Me.ATC_Airline(index).Airline = strarray2(0)
                Me.AircraftView.kcmb_ATC_Parking_Codes.Items.Add(strarray2(5))
                Me.AircraftView.kcmb_ATC_Parking_Codes_Full.Items.Add(strarray2(0))
                Dim row As DataRow = table.NewRow
                row.Item("Airline") = strarray2(0)
                row.Item("ATC_Airline") = strarray2(4)
                row.Item("Parking Code") = strarray2(5)
                table.Rows.Add(row)
                index += 1
                'Me.TSS_ProgressBar1.Value = index

            End If
        Loop


So after all this is done, I select the aircraft from my treeview, this starts reading the selected file
but after all is read, I perform a lookup in the list to see if the "combobox.text" exists in "strarray2" if yes then I update the other comboboxes accordinly so they are all filled out, otherwise I just leave the text that I have from the original ini file.

Above code is done via .NET but since I have a problem reading some undefined Binary files, and saw that
I could do this with delphi I started all over, converting as much as I can to native code, however since I'm completeley rewriting this application I mabey could dump some code, for instance creating database tables etc....

Kind regards, and thanks for the input.
Johan
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 28.09.09 13:06 
Moin!

Das sollte doch eigentlich kein Problem sein, ich halte eher den Ansatz mit den drei ComboBoxen für nicht so gut, da die Einträge ja zusammen gehören - warum dann getrennt ablegen?

Wie du die Daten ins Listview kriegst, sollte ja nun klar sein. Was dir fehlt, ist eine Funktion zum Duchsuchen des Listviews. Das könnte z.B. so gehen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
procedure TForm1.Button2Click(Sender: TObject);
  var
    Str2Look4: String;
    i: Integer;

  function IndexOfCaption(const ACaption: String): Integer;
  begin
    for Result := 0 to ListView1.Items.Count-1 do
      if (ListView1.Items.Item[Result].Caption = ACaption) then
        Exit;
    Result := -1;
  end;

begin
  if InputQuery('Suche','Begriff',Str2Look4) then begin
    i := IndexOfCaption(Str2Look4);
    if (i >= 0then
      ListView1.Items.Item[i].Selected := TRUE
    else
      ListView1.Selected := NIL;
  end;
end;
cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
jcop Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27

WinXP, Vista
Delphi 2009, Vb.NET
BeitragVerfasst: Mo 28.09.09 13:43 
Narses,

Thanks for the input, I will look into this, the reason why I have 3 seperate comboboxes is due to the fact that the original file that I read sometimes has 1 or another value. So when I change something to this
i can write a specific string to for eg. the ICAO field.

below you see a piece of the ini file that original is read and where changes has to be performed.

[fltsim.9]
title=WoA_AIA_B722_VLO-Variglog_OC
model=no_refl
texture=VLO-Variglog_OC
sim=aia_727_200
atc_airline=VELOG
atc_id=
atc_heavy=0
ui_manufacturer=Aardvark
ui_type=Boeing 727-200
ui_variation=Variglog
description=AIA B727-200 for AI use
atc_parking_types=CARGO
atc_parking_codes=VLO
[fltsim.10]
title=WoA_AIA_B722_DAE-DHL Aero Expreso
model=no_refl
texture=DAE-DHL Aero Expreso
sim=aia_727_200
atc_airline=YELLOW
atc_id=
atc_heavy=0
ui_manufacturer=Aardvark
ui_type=Boeing 727-200
ui_variation=DHL Aero Expreso
description=AIA B727-200 for AI use
atc_parking_types=CARGO
atc_parking_codes=DAE

For the DHL Aero Expreso my CSV file has following items
"DHL Aero Expreso",,"DAE"
AS you can see the CSV is missing the atc_airline part, but is is available in the ini file, so
I would like to update the CSV file with the Callsign.
For the VarigLog the CSV file has following data
"Varig Logistica",,"VLO",
As you can see here the ATC_Parking_Codes entry is the same, but the
ui_variation=Variglog doesn't exist, also no callsign is available inside the
file. Here I would like to show a popup to the user asking to replace the name
Variglog with Varig Logistica but let the user decide.

I will close this topic to see if your option provides me with what I need. Again thanks for your input.