求教:请问在delphi里如何将一个文本文档里面的内容写到一个数组里去??? ( 积分: 50 )

  • 主题发起人 主题发起人 rein
  • 开始时间 开始时间
R

rein

Unregistered / Unconfirmed
GUEST, unregistred user!
请问在delphi里如何将一个文本文档里面的内容写到一个数组或字条串里去?????
 
请问在delphi里如何将一个文本文档里面的内容写到一个数组或字条串里去?????
 
变量<br> &nbsp;ts &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:tstrings;<br> &nbsp;s &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; :STRING;<br> &nbsp;f &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; :textfile;<br> &nbsp;i &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; :integer;<br> &nbsp; &nbsp;linecounts:integer; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //总行数<br> &nbsp; &nbsp;currentline:integer; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//当前行数<br><br>程序<br> &nbsp;linecounts := 0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//总行数<br> &nbsp;currentline := 0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //当前行数<br>assignfile(f, filename);<br>reset(f);<br>WHILE NOT eof(f) DO<br> &nbsp; &nbsp;BEGIN<br> &nbsp; &nbsp; &nbsp;readln(f, s);<br> &nbsp; &nbsp; &nbsp;APPLICATION.ProcessMessages;<br> &nbsp; &nbsp; &nbsp;inc(linecounts);<br> &nbsp; &nbsp; &nbsp;StatusBar1.Panels.Items[1].Text := '正在估计数据量大小……';<br>END;<br>reset(f);<br>WHILE NOT eof(f) DO<br> &nbsp; &nbsp; &nbsp;BEGIN<br> &nbsp; &nbsp; &nbsp; &nbsp;readln(f, s);<br> &nbsp; &nbsp; &nbsp; &nbsp;ts.Delimiter := Delimiter[1];<br> &nbsp; &nbsp; &nbsp; &nbsp;ts.DelimitedText := s;<br>    //清空空行数据<br> &nbsp; &nbsp; &nbsp; &nbsp;FOR i := 0 DOWNTO ts.count - 1 &nbsp;DO<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IF ts.strings = '' THEN<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ts.Delete(i);<br> &nbsp; &nbsp; &nbsp; &nbsp;showmessage(ts.CommaText);<br>    //数组里放数据<br><br> &nbsp; &nbsp; &nbsp; &nbsp;inc(currentline);<br> &nbsp; &nbsp; &nbsp; &nbsp;application.ProcessMessages;<br><br> &nbsp; &nbsp; &nbsp; &nbsp;IF currentline &lt;&gt; linecounts THEN<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;StatusBar1.Panels.Items[1].Text := '当前处理数据:' +<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;inttostr(currentline) + '/总数据量' + inttostr(linecounts)<br> &nbsp; &nbsp; &nbsp; &nbsp;ELSE<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;StatusBar1.Panels.Items[1].Text := inttostr(linecounts) +<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'条记录已经处理完毕!';<br> &nbsp; &nbsp; &nbsp; &nbsp;StatusBar1.Panels.Items[2].Text := '数据库中共有' +<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;inttostr(datasource1.DataSet.RecordCount) + '条记录';<br> &nbsp; &nbsp; &nbsp;END;<br> &nbsp; &nbsp;adoquery1.Open;<br>FINALLY<br> &nbsp; &nbsp;result := true;<br> &nbsp; &nbsp;closefile(f);<br> &nbsp; &nbsp;ts.Free;<br> &nbsp;END;
 
接受答案了.
 
后退
顶部