1

我的程序中的这个部分首先将客户广告到文本文件(在公共变量中声明)并将其保存到 texfile。onbutton1click 是搜索编辑框中的字符串并将相关客户详细信息返回到备忘录的过程。添加客户工作正常并添加到文本文件,但是当我搜索它时它不会返回任何到备忘录,只是备忘录标题,memo1。我有什么办法可以解决这个问题?抱歉,我是新手。

  procedure TForm2.btnsaveClick(Sender: TObject);

  begin
     cusfname:= edit1.text ;
     cuslname:= edit2.text;
     adress:= edit3.text;
     phone:= edit4.text;
     password:= edit5.Text;
     AssignFile(F, 'Data.txt');
     append(F);
     WriteLn(F, cusfname);
     WriteLn(F, cuslname);
     WriteLn(F, adress);
     WriteLn(F, phone);
     WriteLn(F, password);
     CloseFile(F);
    end;

   procedure TForm2.Button1Click(Sender: TObject);

   var

     SearchFile : Textfile;
     found: boolean;
     search: string;

    begin
    search := edit1.text;
    Assignfile(SearchFile, 'data.txt');
    Reset(SearchFile);
    found:= false;
    repeat
      found:= search = phone
    until eof(searchfile) or found;
    if found then
    memo1.append(phone);
    memo1.append(cusfname);
    memo1.append(adress);
    if not found then 
      showmessage('member not found');
   end;                           
4

2 回答 2

0

在您的代码中,您不是read()来自文件。在其他类似的问题(可能是您自己的)中:runerror(102) 文件未分配?read()。但我认为你应该使用readln(),甚至更好地使用单元中的TStringListClasses及其LoadFromFile()方法和Lines属性。

于 2010-10-26T06:40:27.910 回答
0

想知道 read 语句在哪里?在 write 函数中有 Write() 语句,但在读取代码中没有 read() 语句?

于 2010-10-24T10:42:20.803 回答