Autor Beitrag
Jagg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 635



BeitragVerfasst: Mo 26.05.03 11:23 
Hallo Leute !

Ich habe eine TStringList erstellt in der DateiNamen hineingeschrieben werden,so ist das auch soweit in Ordung :-)
Aber wenn ich jetzt z.b. einen DateiNamen hinzufüge,der schon in der StringList enthalten ist,will ich,das er den DateiNamen gar nicht reinschreibt !
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
for a := 0 to DatenList.Count-1 do
begin
  DatenList.add(Table1.Tablename);
  DatenList.SaveToFile(ChangeFileExt(Application.ExeName,'.log'));
end;

....ich weiss nicht,wie ich vorgehen soll,das er doppelte Einträge vermeidet !
Könnt ihr mir helfen ???

Jagg !

Moderiert von user profile iconTino: Code- durch Delphi-Tags ersetzt.
Udontknow
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2596

Win7
D2006 WIN32, .NET (C#)
BeitragVerfasst: Mo 26.05.03 11:27 
Nun, du könntest ja einfach eine Funktion schreiben, die nachguckt, ob der String schon in der Liste ist.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
if not (StrIsInList(Str)) then Liste.add...

function StrIsInList(Str:String):Boolean;
var i:integer;
begin
  Result:=False; 
  for i:=0 to List.Count-1 do
    if List[i]=Str then 
    begin
      Result:=True;
      exit;
    end;
end;

Es geht aber auch einfacher:
ausblenden Delphi-Quelltext
1:
2:
Liste.Sorted:=True; 
Liste.duplicates:=dupignore;


Cu,
Udontknow

Moderiert von user profile iconTino: Code- durch Delphi-Tags ersetzt.
Jagg Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 635



BeitragVerfasst: Mo 26.05.03 11:51 
wenn das mit dem sorted und duplicates einfacher geht,warum erkennt das Programm den Befehl nicht !

Ich benutze TStringList
z.b.
DatenList.Sorted erkennt er nicht !
Udontknow
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2596

Win7
D2006 WIN32, .NET (C#)
BeitragVerfasst: Mo 26.05.03 11:56 
Ist Datenlist wirklich eine Variable vom Typ TStringlist? Oder etwa vom Typ TStrings? Die sind ja zuweisungskompatibel. Probiere dann mal TStringlist(Datenlist).Sorted:=True. Oder besser gleich den Variablen-Typen ändern.

Cu,
Udontknow
Jagg Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 635



BeitragVerfasst: Mo 26.05.03 11:58 
ne ist vom typ Tstring
Jagg Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 635



BeitragVerfasst: Mo 26.05.03 11:59 
tstrings
Udontknow
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2596

Win7
D2006 WIN32, .NET (C#)
BeitragVerfasst: Mo 26.05.03 12:05 
Es gibt eine Edit-Funktion... :roll:

Wie ich gerade schon sagte, entweder abändern (TStrings -> TStringlist) oder aber casten:

ausblenden Delphi-Quelltext
1:
2:
TStringlist(Datenlist).Sorted:=True;
TStringlist(Datenlist).Duplicates:=DupIgnore;


Cu,
Udontknow


Moderiert von user profile iconTino: Code- durch Delphi-Tags ersetzt.
Jagg Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 635



BeitragVerfasst: Mo 26.05.03 12:20 
danke,ich habe das schon vorher gehabt,aber trotzdem danke
Udontknow
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2596

Win7
D2006 WIN32, .NET (C#)
BeitragVerfasst: Mo 26.05.03 12:23 
Wie jetzt? Jetzt bin ich verwirrt. :?!?: Funktioniert es, oder funktioniert es nicht?

Cu,
Udontknow
Jagg Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 635



BeitragVerfasst: Mo 26.05.03 12:55 
ja es geht danke