Autor Beitrag
unstable
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 32

windows xp/2000
D5
BeitragVerfasst: Di 21.09.04 11:33 
yo,

ich habe ein neues problem :)

ich habe eine datei,text.txt.
ich will das wenn da 150 oder mehr Sätze drin sind, das sie dann gelöscht wird.
mit FileSize funktioniert das nicht so wie ich das will.
weiss sons noch jemand etwas?

greetz,
-_-unstable

_________________
why bother with a sig?
bEaST
Hält's aus hier
Beiträge: 7



BeitragVerfasst: Di 21.09.04 11:38 
Guck mal auf www.delphi-source.de, da findest du in der Delphi Library eine Anleitung wie man die Sections einer INI-Datei zählt, vielleicht hilft dir das ja weiter...
Martin77
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 282

XP Prof
D6 Prof, D7 Personal, D7 Enterprise, D8 personal
BeitragVerfasst: Di 21.09.04 11:51 
Alternativ eine Stringliste. dann kannste mit Count die Anzahl der Zeilen abfragen und daraufhin dann eine entscheidung treffen. Wenn es sich um eine LogDatei handelt kannste dann auch die ältesten einträge rauswerfen.
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Di 21.09.04 11:53 
Du könntest die Datei einfach in eine Stringlist einlesen (LoadFromFile glaub ich) und prüfen, wieviel Strings darin stehen. Meines Wissens gibt es ansonsten keine Funktion für die Anzahl der Zeilen in einem TextFile.
Bitte korrigiert mich wenn das nicht stimmt.
.Chef
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1112



BeitragVerfasst: Di 21.09.04 12:09 
unstable hat folgendes geschrieben:
wenn da 150 oder mehr Sätze drin sind
Wenn es sich um Sätze im grammatischen Sinne handelt, kannst du die Datei auch in einen Puffer lesen ...
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
var
  f : file;
  a, b : Integer;
  x : array of Char;
begin
  AssignFile(f,'text.txt');
  Reset(f,1);
  SetLength(x,FileSize(f));
  BlockRead(f,x[0],FileSize(f));
  CloseFile(f);

... und anschließend die Punkte zählen.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
  b:=0;
  for a:=0 to Length(x)-1 do
    if x[a] = '.' then Inc(b);
  if b >= 150 then DeleteFile('text.txt');

:)

_________________
Die Antworten auf die 5 häufigsten Fragen:
1. Copy(), Pos(), Length() --- 2. DoubleBuffered:=True; --- 3. Application.ProcessMessages bzw. TThread --- 4. ShellExecute() --- 5. Keine Vergleiche von Real-Typen mit "="!
unstable Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 32

windows xp/2000
D5
BeitragVerfasst: Di 21.09.04 12:33 
Titel: thx
yo,

das mit IniList : TStringList hatte ich auch probiert.
hat auch net geklappt.
aber der trick von .chef hat (wie immer) gut funktioniert.
ich musste zwar nur noch ein zeichen rein setzen was man zählen konnte(#)...
aber es macht was es machen soll.

thx .chef,
again :D,
-_-unstable

_________________
why bother with a sig?
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Di 21.09.04 12:43 
Da würde mich aber doch interessieren, warum es nicht mit der StringList funktioniert. Sind es tatsächlich Sätze im grammatischen Sinn? Oder hatten die (Daten-)sätze kein Zeilenende? Oder was?
unstable Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 32

windows xp/2000
D5
BeitragVerfasst: Di 21.09.04 13:02 
die 'sätze' sehen so aus:

#event: 21.09.2004:13:39:05: started application

ich habe das # am anfang um die sätze zählen zu können.
es sind also keine normale sätze nein.
es ist für ein log bestimmt.

_________________
why bother with a sig?
Martin77
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 282

XP Prof
D6 Prof, D7 Personal, D7 Enterprise, D8 personal
BeitragVerfasst: Di 21.09.04 13:04 
Das soltle eine StringListe aber auch können, merkwürdig. Wie fügst du die Sätze denn hinzu?
unstable Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 32

windows xp/2000
D5
BeitragVerfasst: Di 21.09.04 13:08 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
  AssignFile(myFile,'text.txt');
  //wenn mehr als 150 Sätze, dann wird sie gelöscht
  countFile;
  
  if FileExists('text.txt') then
  begin
    Append(myFile);
  end
  else
    ReWrite(myFile);
  WriteLn(myFile);
  Write(myFile,'#event: ' + ev);
  CloseFile(myFile);


Moderiert von user profile iconChristian S.: Code- durch Delphi-Tags ersetzt.

_________________
why bother with a sig?
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Di 21.09.04 13:09 
Ich vermute mal, dass da ein CR-LF zwischen den Zeilen fehlt.
EDIT: Sehe gerade deinen Source. Theoretisch fehlt da nix. Hmmm.
Martin77
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 282

XP Prof
D6 Prof, D7 Personal, D7 Enterprise, D8 personal
BeitragVerfasst: Di 21.09.04 13:14 
Wie hast du es denn mit der StringListe probiert?