Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

TStirngList and LoadFromFile

0 views
Skip to first unread message

Ted C. Hall

unread,
Oct 19, 1998, 3:00:00 AM10/19/98
to
I am using Delphi 2 and Windows 95.
I wish to extract data from a comma delimited file to provide values for
several variables. I have been trying to use a TStringList but have run into
a problem getting all of the items of the delimited file placed into the
StringList. Below is an example of my code.

type
TStringListForm = class(TForm)
Edit1: TEdit;
DoButton: TButton;
procedure FormCreate(Sender: TObject);
procedure DoButtonClick(Sender: TObject);
public
File1: TStringList;
FileE: TStringList;
end;

var
StringListForm: TStringListForm;

implementation

procedure TStringListForm.FormCreate(Sender: TObject);
begin
File1 := TStringList.Create;
FileE := TStringList.Create;
end;

procedure TStringListForm.DoButtonClick(Sender: TObject);
var
FileName: string;
begin
FileName := Edit1.Text;
try
File1.LoadFromFile(FileName);
FileE.CommaText := File1.Text;
finally
File1.Free;

At this point if I look at File1.Count before freeing the return is the
number of records in the comma delimited file. If I look at FileE.Count the
return is a partial number of record items. Each record has 87 items of
data and the delimited file can have as many as 800 records. This relates to
approx. 70,000 items per file. The number returned for FileE.Count is
typically between 915 and 930. I have tried this same code on other
computers with larger memory with no difference in the outcome for
FileE.Count. The capacity for a StringList is much larger than what I am
using so how come I don't get all the items loaded into FileE?
Thanks for your help.
Ted Hall
T_...@msn.com or t...@thoracingnet.com

Peter Below

unread,
Oct 19, 1998, 3:00:00 AM10/19/98
to
> I wish to extract data from a comma delimited file to provide values for
> several variables. I have been trying to use a TStringList but have run into
> a problem getting all of the items of the delimited file placed into the
> StringList. Below is an example of my code.
snip
> File1.LoadFromFile(FileName);
> FileE.CommaText := File1.Text;

>
> At this point if I look at File1.Count before freeing the return is the
> number of records in the comma delimited file. If I look at FileE.Count the
> return is a partial number of record items. Each record has 87 items of
> data and the delimited file can have as many as 800 records. This relates to
> approx. 70,000 items per file. The number returned for FileE.Count is
> typically between 915 and 930. I have tried this same code on other
> computers with larger memory with no difference in the outcome for
> FileE.Count. The capacity for a StringList is much larger than what I am
> using so how come I don't get all the items loaded into FileE?

Ted,

i think there was a little bug in D2's CommaText implementation regarding
large input strings, if i remember correctly. Instead of trying to parse the
complete file at once do it record by record

File1.LoadFromFile(FileName);
for i:= 0 To File1.count-1 do begin
FileE.CommaText := File1[i];
...process the fields for this record
end;

Peter Below (TeamB) 10011...@compuserve.com)
No e-mail responses, please, unless explicitely requested!


0 new messages