Autor Beitrag
adfontes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 82

Win7 (64bit), WinXP
Delphi 2010 Prof, Delphi XE2 (Trial)
BeitragVerfasst: Do 02.03.06 14:54 
Hi,

ich habe eine Listbox, die mit Namen aus einer Datei gefüllt wird. Die Datei beinhaltet ein Record, in dem auch noch Daten zu den Namen liegen. Ein Name kann auch mehrmals vorkommen und da entsteht das Problem: Ich füge die Namen folgendermaßen in die ListBox ein:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
AssignFile(DATEI_B,'C:\Infos.dat');
Reset(DATEI_B);
ListBox2.Items.Clear;
While NOT EOF(DATEI_B) do
 begin
   Read(DATEI_B,tmp);
   ListBox2.Items.Add(tmp.Name);
 end;
closeFile(DATEI_B);
end;


Wenn jetzt ein Name doppelt vorkommt, fügt er ihn logischerweise ja auch nochmal in die ListBox ein. Die Frage ist jetzt, ob es eine Möglichkeit gibt diese Dopplungen zu vermeiden? Am einfachsten wird wohl eine If-Bedingung über dem *.Add Befehl, nur woher bekomme ich die bisher in der Liste stehenden Daten?


:(
ich hoffe ihr versteht das Problem und könnt mir dabei helfen

adfontes
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 02.03.06 14:57 
Moin!

Probier das mal so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
  AssignFile(DATEI_B,'C:\Infos.dat');  
  Reset(DATEI_B);  
  ListBox2.Items.Clear;  
  while (NOT Eof(DATEI_B)) do begin
    Read(DATEI_B,tmp);
    if (ListBox2.Items.IndexOf(tmp.Name) = -1) then
      ListBox2.Items.Add(tmp.Name);  
  end;  
  CloseFile(DATEI_B);
end;

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.


Zuletzt bearbeitet von Narses am Do 02.03.06 15:28, insgesamt 1-mal bearbeitet
adfontes Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 82

Win7 (64bit), WinXP
Delphi 2010 Prof, Delphi XE2 (Trial)
BeitragVerfasst: Do 02.03.06 15:19 
Vielen, vielen Dank ! :) :) :)

funktioniert super :) :) :)