Board index » delphi » How to read textfiles - ReadLn() Problem

How to read textfiles - ReadLn() Problem

I have a problem with the ReadLn() procedure.
If I have a textfile andtry to use ReadLn() then
ReadLn() skips some of the EOL characters.
Is there a procedure which can read textfiles
like the Tstrings.LoadFromFile() procedure?

Thanx!

 

Re:How to read textfiles - ReadLn() Problem


Quote
> I have a problem with the ReadLn() procedure.
> If I have a textfile andtry to use ReadLn() then
> ReadLn() skips some of the EOL characters.
> Is there a procedure which can read textfiles
> like the Tstrings.LoadFromFile() procedure?

There is no problem with the readln function.
There may, however, be a problem in your
use of it.  Post the code which isn't working
for you, and we'll help you out.

--
--------------------------
Eric Lawrence
Delta Programming Group
Delta...@juno.com

Re:How to read textfiles - ReadLn() Problem


Quote
alf...@xs4all.nl (Blitter) wrote:
>I have a problem with the ReadLn() procedure.
>If I have a textfile andtry to use ReadLn() then
>ReadLn() skips some of the EOL characters.

    I have never had problems with the Readln instruction: could you send
a piece of your code to the newsgroup so we can perhaps help you...

Quote
>Is there a procedure which can read textfiles
>like the Tstrings.LoadFromFile() procedure?

>Thanx!

--
 AVONTURE Christophe                    0 0      The Crazy Programmer
 Christophe.Avont...@is.belgacom.be      |         Brussels (Belgium)
 Uses Standard_Disclaimer;              \_/            Happy New Year
 French Pascal programmation site     http://www.mygale.org/07/jmy51/

Re:How to read textfiles - ReadLn() Problem


Quote
Blitter wrote:

> I have a problem with the ReadLn() procedure.
> If I have a textfile andtry to use ReadLn() then
> ReadLn() skips some of the EOL characters.
> Is there a procedure which can read textfiles
> like the Tstrings.LoadFromFile() procedure?

> Thanx!

Are the strings in your text files, Pascal based
strings: do they end up with #13#10?
Unix style strings will not be properly read...
ReadLn() works fine, if these strings are terminated
by #13#10...

M

Re:How to read textfiles - ReadLn() Problem


This is a cheat post because I have annoying problem involving readln
with text files, and this seemed like the ideal mini-forum to discuss
it.

I want to read and write text which may be more that 255 characters in
length.  To do this I use PChars because of the extra length.  The
call Writeln(Textfile,PChar) works perfectly.  The line
Readln(Textfile,PChar) generates a compiler error 'Can't read or write
variables of this type'.  Seeing as how the write works perfectly, you
can understand my frustration at the error message.   What do I do?

Btw, I don't think it makes a difference but extended syntax is turned
on anyway.  Oh yeah, I'm using Delphi 1.0

Thanks, Michael.

Re:How to read textfiles - ReadLn() Problem


Quote
In article <32de0838.9220...@news.xs4all.nl> alf...@xs4all.nl (Blitter) writes:
>Path: news3.cac.psu.edu!howland.erols.net!surfnet.nl!news.unisource.nl!xs4all!xs4all!usenet
>From: alf...@xs4all.nl (Blitter)
>Newsgroups: comp.lang.pascal.delphi.misc
>Subject: How to read textfiles - ReadLn() Problem
>Date: Thu, 16 Jan 1997 11:01:23 GMT
>Organization: XS4ALL, networking for the masses
>Lines: 7
>Message-ID: <32de0838.9220...@news.xs4all.nl>
>Reply-To: alf...@xs4all.nl
>NNTP-Posting-Host: ipabo.xs4all.nl
>Mime-Version: 1.0
>Content-Type: text/plain; charset=us-ascii
>Content-Transfer-Encoding: 7bit
>X-XS4ALL-Date: Thu, 16 Jan 1997 12:04:50 MET
>X-XS4ALL-User: alf...@xs4all.nl on ipabo.xs4all.nl
>X-Newsreader: Forte Agent .99f/32.289
>I have a problem with the ReadLn() procedure.
>If I have a textfile andtry to use ReadLn() then
>ReadLn() skips some of the EOL characters.

Had the same problem. This happens when you use "if not SeekEof(Fil)" Very
strange, but doesn't happen with plain "if not Eof(Fil)". No idea why.

Re:How to read textfiles - ReadLn() Problem


In article <5bv1ss$...@newsman.murdoch.edu.au>,
   mi...@cleo.murdoch.edu.au (Michael Lee) wrote:
]-I want to read and write text which may be more that 255 characters in
]-length.  To do this I use PChars because of the extra length.  The
]-call Writeln(Textfile,PChar) works perfectly.  The line
]-Readln(Textfile,PChar) generates a compiler error 'Can't read or write
]-variables of this type'.  Seeing as how the write works perfectly, you
]-can understand my frustration at the error message.   What do I do?

use zero-based character arrays instead. with extended syntax
enabled, zero-based character arrays can be used anywhere you'd
ordinarily us a PChar; e.g.

  Type
    TBigString = array[0..2047] of char;
  Var
    MyBigString : TBigString;
    BigLength   : integer;
    MyPChar     : PChar;

  BEGIN
    readln(MyTextFile, MyBigString);
    BigLength := StrLen(MyBigString);
    MyPChar := MyBigString;
    [...]
  END;

chapter 15 of the Object Pascal Language Guide has more details.

Mark Vaughan

]-
]-Btw, I don't think it makes a difference but extended syntax is turned
]-on anyway.  Oh yeah, I'm using Delphi 1.0
]-
]-Thanks, Michael.
]-

Re:How to read textfiles - ReadLn() Problem


Quote
m.a.vaug...@larc.nasa.gov (Mark Vaughan) wrote:
>In article <5bv1ss$...@newsman.murdoch.edu.au>,
>   mi...@cleo.murdoch.edu.au (Michael Lee) wrote:
>]-I want to read and write text which may be more that 255 characters in
>]-length.  To do this I use PChars because of the extra length.  The
>]-call Writeln(Textfile,PChar) works perfectly.  The line
>]-Readln(Textfile,PChar) generates a compiler error 'Can't read or write
>]-variables of this type'.  Seeing as how the write works perfectly, you
>]-can understand my frustration at the error message.   What do I do?

>use zero-based character arrays instead. with extended syntax
>enabled, zero-based character arrays can be used anywhere you'd
>ordinarily us a PChar; e.g.

>  Type
>    TBigString = array[0..2047] of char;
>  Var
>    MyBigString : TBigString;
>    BigLength   : integer;
>    MyPChar     : PChar;

>  BEGIN
>    readln(MyTextFile, MyBigString);
>    BigLength := StrLen(MyBigString);
>    MyPChar := MyBigString;
>    [...]
>  END;

Yup.  Found that out last week.  FYI, you can use New() to allocate a
pointer to the TBigString if you want.
++++
William Sorensen
te...@ia.net

Other Threads