开发者

searching a text file the writing result to memo, lazarus

开发者 https://www.devze.com 2023-01-20 17:13 出处:网络
this segment in my program first ads a customer to a textfile (declared in public variables) and saves it to a texfile. onbutton1click is the procudere to search the string thats in the editbox and re

this segment in my program first ads a customer to a textfile (declared in public variables) and saves it to a texfile. onbutton1click is the procudere to search the string thats in the editbox and return the relevant customer details to memo. the add customer works fine and adds to textfile, however when i search it returns nothing onto the memo, just the memo caption, memo1. any way i can resolve this? sorry im a newb to this.

  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);
     W开发者_运维问答riteLn(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;                           


wonder where are the read statements? In the write function you have Write() statements, but in the reading code no read() statements?


In your code you do not read() from file. In other similar question (probably your own): runerror(102) file not assigned? there is read(). But I think you should use readln(), or even better use TStringList class from Classes unit with its LoadFromFile() method and Lines property.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号