X-Git-Url: http://www.lcore.org/git/lcore.git/blobdiff_plain/a1858883733a454b6ffb73aa263ef5badc2a1d07..c1c7500bc32248d67b6cf7903a6db7b15e2cd1c9:/readtxt2.pas diff --git a/readtxt2.pas b/readtxt2.pas index 84c5765..12bea5a 100644 --- a/readtxt2.pas +++ b/readtxt2.pas @@ -34,7 +34,7 @@ type constructor create(asourcestream: tstream; adestroysourcestream:boolean); constructor createf(filename : string); - function readline:string; + function readline:ansistring; function eof:boolean; destructor destroy; override; private @@ -44,6 +44,7 @@ type currenteol,preveol:integer; fileeof,reachedeof:boolean; eoltype:integer; + procedure checkandread; end; implementation @@ -54,17 +55,26 @@ begin sourcestream := asourcestream; destroysourcestream := adestroysourcestream; - if sourcestream.Position >= sourcestream.size then fileeof := true; + //if sourcestream.Position >= sourcestream.size then fileeof := true; bufpointer := bufsize; - destroysourcestream := false; end; -constructor treadtxt.createf(filename : string); +constructor treadtxt.createf(filename: string); begin create(tfilestream.create(filename,fmOpenRead),true); end; +procedure treadtxt.checkandread; +begin + if bufpointer >= numread then begin + numread := sourcestream.read(buf,bufsize); + bufpointer := 0; + if numread = 0 then fileeof := true; + + end; +end; + function treadtxt.readline; var a,b,c,d:integer; @@ -72,11 +82,7 @@ begin result := ''; repeat - if bufpointer >= bufsize then begin - numread := sourcestream.read(buf,bufsize); - bufpointer := 0; - if sourcestream.Position >= sourcestream.size then fileeof := true; - end; + checkandread; b := numread-1; {core search loop begin} @@ -97,7 +103,8 @@ begin setlength(result,c+b); move(buf[bufpointer],result[c+1],b); bufpointer := numread; - if numread < bufsize then begin + if fileeof then begin + {we reached the end of the file, return what we have} reachedeof := true; exit; end; @@ -134,8 +141,8 @@ end; function treadtxt.eof:boolean; begin - - result := ((bufpointer >= bufsize) and fileeof) or reachedeof; + checkandread; + result := ((bufpointer >= numread) and fileeof) or reachedeof; end; destructor treadtxt.destroy;