Autor Beitrag
tmkb
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 59



BeitragVerfasst: Fr 17.01.03 16:45 
Hallo,

Kenne mich nicht so gut in Delphi aus, darum woltle ich fragen wie eine einfache schleife programmiert wird?
Und zwar folgendes: Ich habe ein Memo welches ungefähr so aussieht:

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
C:\ordner1\bla.txt
C:\ordner1\bla2.txt
C:\ordner1\bla3.txt
C:\ordner1\bla4.txt
C:\ordner1\bla5.jpg
C:\ordner1\bla.exe
C:\ordner2\bla.txt
C:\ordner2\bla2.txt


Jetzt soll er in einer schleife jede einzelne Zeile durchgehen und checken ob die File existiert (If FileExists...). Wenn sie existiert dann soll es bei der jeweiligen Zeile noch "existiert" dazuschreiben, dass das memo nachdem die schleife durchgelaufen ist, so aussieht:

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
C:\ordner1\bla.txt existiert
C:\ordner1\bla2.txt existiert
C:\ordner1\bla3.txt existiert
C:\ordner1\bla4.txt existiert
C:\ordner1\bla5.jpg existiert
C:\ordner1\bla.exe existiert
C:\ordner2\bla.txt existiert
C:\ordner2\bla2.txt existiert


Danke für alle Hilfen!
tmkb
matze
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Fr 17.01.03 16:52 
also:

überrüfen oob eine datei existiert kannst du mit FileExists.

das memo zeile für zeile durchgehen kannst du mit
ausblenden Quelltext
1:
2:
3:
4:
5:
for a := 0 to memo1.lines.count do begin

//code

end;


a enthält dann immer die aktuelle zeilen-nummer

den text einer zeile bekommst du mit memo1.lines[zeilennummer];

viel spass noch damit !!

_________________
In the beginning was the word.
And the word was content-type: text/plain.
torstenheinze
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 461



BeitragVerfasst: Fr 17.01.03 16:54 
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
var 
  i, k: integer;
begin
  k := 0;
  for i := 0 to memo1.lines.count do
    begin
      if fileexists(memo1.lines[k]) then
        memo1.lines[k] := memo1.lines[k] + ' existiert';
      inc(k);
    end;
end;


Moderiert von user profile iconTino: Code-Tags hinzugefügt.
torstenheinze
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 461



BeitragVerfasst: Fr 17.01.03 16:55 
@matze , warst schneller :wink:
naja, ich hab mal meinen codenoch geprüft, und dat hat nen bischen gedauert
tmkb Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 59



BeitragVerfasst: Fr 17.01.03 17:06 
danke, funktioniert!
torstenheinze
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 461



BeitragVerfasst: Fr 17.01.03 17:10 
gern geschehen
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Fr 17.01.03 20:18 
@torstenheinze: Warum benutzt Du in Deinem Code-Beispiel die Variable K? Außerdem wird es einen Fehler geben wenn ich Deinen Code benutze. Wenn Du bei 0 anfängst zu zählen dann musst Du Count -1 als Endwert benutzen:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
Var 
  Idx: Integer; 
Begin
  For Idx := 0 to Memo1.Lines.Count -1 Do
    If FileExists (Memo1.Lines [Idx]) Then
      Memo1.Lines[k] := Memo1.Lines[k] + #32 + 'existiert';
End;


Gruß
TINO
torstenheinze
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 461



BeitragVerfasst: Fr 17.01.03 20:24 
ja, hast ja recht (ich weiß das es 0-basiert ist), aber es gibt trotzdem kein fehler, bei mir zumindest.

das mit k:
also manchmal braucht man noch mal eine variable, die sich bei einer schleife erhöht, doch diese hier (also k) kann man auch manuell verändern ( k:= 2)
bei i geht das nicht, weil es für die schleife dient.
hast ja recht, die wird hier net benutzt :roll:
torstenheinze
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 461



BeitragVerfasst: Fr 17.01.03 20:26 
warum schreibst du da #32 hin, du kannst doch auch einfach das so schreiben:
' existiert'

und halt ein leerzeichen einfügen, also hast du auch was zu viel geschrieben