Click here to Skip to main content
16,016,022 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
How Can I Add Data(String type or integer and ...) To 'TStringList' From a 'TextFile'and then Count the same Data(this=5, or=3 ,123=12 for example) at last show into the 'ListBox' or 'TextBox' something like that,Please help me anyone who knows Delphi well.
Posted

1 solution

To add data, you'll do something like:
Delphi
SLst := TStringList.Create;
//To add string to a TStringList:
SLst.Add('This is a string');
//or
SLst.Add(VariableName);

//To add integer
SLst.Add(IntToStr(55));
//or
SLst.Add(IntToStr(VariableName));

you'll define SLst by:
Delphi
var
  SLst: TStringList;


And if you want to load it from a textfile:
Delphi
SLst.LoadFromFile('C:\myfile.txt');

And what do you mean by count the same data? You mean to count how much lines there are in the File? If yes, then:
Delphi
Count := SLst.Count;


But if you want to show the data in a Memo, then do the following instead of all the above code:
Delphi
Memo1.Lines.LoadFromFile('C:\myfile.txt');
Count := Memo1.Lines.Count;


I hope my answer helped.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900