本人想作一个密码登陆窗口,先用一个写文件的例子来试一下,本意是:在BUF 处停下来,打印出,但不知怎样,却全部打印出来了,我百思不得其解!错在哪?请各位大虾指点下!如有关于密码登陆的例子,顺便赐一个,本人感激不尽!Thang you very much!这是D:\File\Text.cfg的内容!
MyText.file  MyText1.file
Second.file  Second1.file
Three.file   Three1.file
Four.file    Four1.file
Five.file    Five1.file
six.file     six1.file  
procedure TForm1.Button1Click(Sender: TObject);
var
  MyFile:TextFile;
  Buf,buf1,buf2:string[12];
begin
  buf2:='second.file';
  AssignFile(MyFile,'D:\File\Text.cfg');
  Reset(MyFile);
  Memo1.Clear;
  Readln(MyFile,buf,buf1);
  while((Trim(buf)<>Trim(buf2)) and not Eof(MyFile))  do
  begin
    Memo1.Lines.Add(buf);
    Readln(MyFile,buf,buf1);
  end;
     Memo1.Lines.Add(buf);
     closefile(Myfile);
end;end.

解决方案 »

  1.   

    你跟踪一下buf的值你就知道为什么了,呵呵。
      

  2.   

    Memo1.Clear;
      Readln(MyFile,buf,buf1);
      while((Trim(buf)<>Trim(buf2)) and not Eof(MyFile))  do
      
    在上面加那行前面设置断点,运行到这以后按F8单步执行,想看时讲鼠标点及想看的变量就可以看值,或者.....方法很多,看看书,一句两句说不清。单步执行时,每次执行到while((Trim(buf)<>Trim(buf2)),看一下buf跟buf2得值就知道为什么了。
      

  3.   

    受不了你了,替你调试了一下,问题很简单buf2:='second.file';
    其中的second.file 改成 Second.file就好了,字符串比较是区分大小写的。不过我要说你,还需要努力呀,兄弟,最起码要学会调试呀,写程序调试是最关键的,此问题通过调试跟踪,问题很容易发现。
      

  4.   

    大哥,不是我不努力,我是一名大三学生,学DELPHI不过才3个月左右!谢谢大哥指点!