Autor Beitrag
Jacko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 20



BeitragVerfasst: Di 09.08.05 07:26 
Hi,
ich habe ein Programm geschrieben, dass mir ermöglicht aus einer .txt-datei daten zu lesen und in einen StringGrid zu schreiben. Bei jedem Semikolon in der Text-Datei wird eine Zelle im StringGrid weitergesprungen.

z.B.
000;Frequenz;0
001;Kühlkörpertemperatur;4
002;Strombegrenzung;18


Das Problem ist am Zeilenende, es wird jeweils der letzte Abschnitt(z.B. 0||001) in einer Zelle abgelegt.
Mit welcher Anweisung lasse ich ein Zeilenende erkennen.
:?


danke im voraus
WeBsPaCe
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Di 09.08.05 07:29 
Du kannst prüfen, ob das Zeichen, bei den du im Moment bist ein #13 ist und das nächste ein #10. Also jeweils ASCII-Code. Das ist der Zeilenumbruch. Und sobald ein Zeilenumbruch da war, ist neue Zeile da.
MisterBum
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 107



BeitragVerfasst: Di 09.08.05 08:33 
So viel wie ich weiß gibt es bei Textdateien den Befehl EOL (End of Line). Damit kannst du das ganze überprüfen...
WeBsPaCe
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Di 09.08.05 08:41 
user profile iconMisterBum hat folgendes geschrieben:
So viel wie ich weiß gibt es bei Textdateien den Befehl EOL (End of Line). Damit kannst du das ganze überprüfen...

Joa. Je nachdem wie du die Textdatei lädst kann die das helfen:

Zitat:
Tests whether the file pointer is at the end of a line.
Unit
System
Category
text file routines
Delphi syntax:
function Eoln [(var F: Text) ]: Boolean;
Description
In Delphi code, Eoln tests whether the current file position is the end-of-line of a text file. F, if specified, is a text file variable. If F is omitted, the standard file variable Input is assumed.
Eoln(F) returns true if the current file position is at an end-of-line or if Eof(F) is true; otherwise, Eoln(F) returns false.


Ansonsten nimmst du eben die Funktion da:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
function IsZeilenende(Text: String; Pos: Integer): Boolean;
begin
if Length(Text) < Pos then
  Result := True;
if Length(Text) = Pos then
  Result := False;
if Length(Text) > Pos then
  if (Text[Pos]+Text[Pos+1]) = (Chr(13)+Chr(10)) then
    Result := True
  else
    Result := False;
end;
LigH
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 239

Win98SE, Win2000SP4
D7
BeitragVerfasst: Di 09.08.05 13:12 
Ich verstehe die Frage nicht.

ReadLn(TextFile, String) liest eine Zeile bis zum Ende aus einer Textdatei. Das Zeilenende wird da schon von den Text-Lese-Routinen selber erkannt. Also - wozu selber testen?
MisterBum
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 107



BeitragVerfasst: Di 09.08.05 15:28 
Eigentlich hat LigH Recht.
Bei readln wird die komplette Zeile bis zum Ende eingelesen...
WeBsPaCe
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Di 09.08.05 15:33 
Ist doch irrelevant. Vielleicht benutzt er gar kein ReadLn. ;) Hat schonmal jemand in PHP fgets genommen? Da kann man so eine Funktion auch gebrauchen. ;)
LigH
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 239

Win98SE, Win2000SP4
D7
BeitragVerfasst: Di 09.08.05 18:04 
Dann sollte aber bloß keiner den Fehler machen, "file of Char" oder "file of Byte" zu verwenden. Insbesondere beim Schreiben ist das langsamer, als man sich vorstellen kann!

- Der korrekte Weg, auf Binärdateien zuzugreifen, ist "BlockRead/BlockWrite".
- Der korrekte Weg, auf Textdateien zuzugreifen, ist "ReadLn/Write{Ln}".

Zumindest für die "herkömmlichen Techniken". Also mal abgesehen von Stringlist-Methoden, oder FileStreams.