Re: Strings



On 2006.06.07 11:22, Allan Brocklehurst wrote:
In this case the record I'm reading into a variable is 10258 characters.
Problem is that I'm only getting a max of 4096 characters into the
variable.

Sounds like a buffer size is being exceeded somewhere. I know that
Windows defaults to using 4096 as the buffer size for COM ports - I
don't know if it also applies to text files. (Com ports are opened with
the same Windows API CreateFile function that is used to open files.)

The following code works fine under Delphi 7 and Windows 2003:
procedure TForm1.Button1Click(Sender: TObject);
var
f: TextFile;
s: string;
begin
assignFile(f,'test.txt');
reset(f);
readln(f,s);

memo.Lines.Add('Length of first line is ' + inttostr(length(s)) );
memo.Lines.Add(s);
closeFile(f);
end;

I don't know how big your files are, but an alternative approach is to
read the entire file at once. eg:
function ReadStringFromFile(const fileName: string): string;
var
f: File;
size: integer;
begin
assignFile(f,fileName);
reset(f,1);
try
size := FileSize(f);
SetLength(result,size);
BlockRead(f,result[1],size);
finally
CloseFile(f);
end;
end;


--
Ed Vander Hoek
web: www.getawaymaps.com
email: ed.vanderhoek at ...
Gastown Command Line Parser
.