下面是我现在的代码,现在能实现了从TXT文件从读取信息,我是根据Edit1.Text中字符串中的时间来读取的,如果Edit1.Text中字符串中的时间是2007-05-08 ,我TXT文件中最后的时间是2007-05-08 那么我在MEMO中显示的也就是2007-05-08 这天纪录的内容。如果我Edit1.Text中字符串中的时间是2007-05-01,那么 MEMO中显示的也就是2007-05-01 到2007-05-08  这几天的内容。 请问怎么样写才能只显示Edit1.Text中字符串中的时间对应的内容,其他时间纪录的内容不显示var
  s1,s2,S,ALLText:string;
  F:textfile;
  nPosBegin,nPosEnd:integer;
begin  Edit1.Text:=ShellTreeView1.Path;
  s1:=ExtractFileName(Edit1.Text);
  nPosBegin:=Pos(',',s1);
  nPosEnd:=LastDelimiter(',',s1);
  s2:=Copy(s1,nPosBegin+1,nPosEnd-nPosBegin-1);
//  showmessage(s2);   Assignfile(F,'E:\operview参数备份\Readme.txt');
   reset(F);
   while not EOF (F) do begin
   readln(F,S);
   if CompareStr(S,s2)=0     then
     while not EOF (F) do begin
       readln(F,S);
       ALLText:=ALLText + S+#13#10;
       end;
       Memo1.Clear;
       memo1.Text:=ALLText;     
   end;
   closefile(F);
end;

解决方案 »

  1.   

    我用ss:=strtodatetime(S);判断读出的字符串是不是时间,可是出错了
      

  2.   

    把你的txt文件的内容也贴出来看看,,
      

  3.   

    txt文件里面的格式:
    2007-04-30   16-16-32dfssdfd
    155354522007-04-30   16-21-38121212
    WW
    受到2007-05-08   08-17-54雁荡山
    雁荡山
    雁荡山
      

  4.   

    你应该用TStringList
    AStringList.LoadFromFile(...);
    for I:=0 to AStringList.Count-1 do begin
      if Pos(AStringList[I], YourStr)=1 then 
     ...
    end;