X-Git-Url: http://www.lcore.org/git/lcore.git/blobdiff_plain/e27ef2c6aab3a2a8051314bd37bb3b2386775f36..87fed35010bb66b6183b06b01adb356dbefeefe6:/readtxt2.pas diff --git a/readtxt2.pas b/readtxt2.pas index a5f7de4..12bea5a 100644 --- a/readtxt2.pas +++ b/readtxt2.pas @@ -44,6 +44,7 @@ type currenteol,preveol:integer; fileeof,reachedeof:boolean; eoltype:integer; + procedure checkandread; end; implementation @@ -54,9 +55,8 @@ 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); @@ -65,6 +65,16 @@ begin 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;