delphi建立txt,通过文本框来写入数据...帮帮忙把....

解决方案 »

  1.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      MyFile :TextFile;
    begin
      AssignFile(MyFile,'C:\Test.txt');
      if FileExists('C:\Test.txt') then
        Append(MyFile) \\当文件存在时
      else
        Rewrite(MyFile);\\当文件不存在时。
      Writeln(MyFile,Edit1.Text);
      CloseFile(MyFile);
    end;
      

  2.   

    Memo.loadFormFile('txt文件)
    Memo.SaveToFile('txt文件)
      

  3.   

    var  MyList:TStringList;
    // 读操作
    begin
      MyList:=TStringList.Create;
      MyList.Clear;
      FileName:=FilePath+'asd.TXT';
      MyList.LoadFromFile(FileName);
      MyList.Free;
    end;
    // 写操作
    begin
      MyList:=TStringList.Create;
      MyList.Clear;
      FileName:=FilePath+'asd.TXT';
      MyList.SaveToFile(FileName);
      MyList.Free;
    end;明白了吗?
      

  4.   

    // 写操作
    begin
      MyList:=TStringList.Create;
      ......    // 写文本到 MyList
      FileName:=FilePath+'asd.TXT';
      MyList.SaveToFile(FileName);
      MyList.Free;
    end;
      

  5.   

    你是想要把文本框里的数据保存到txt文件里吧。这种例子网上很多,百度下就有了,发个我写的吧。仅供参考。需要再uses引用些东西
    procedure WriteTxt(sFileName, sText: String);
    Var 
      txtfile:TextFile;
      h:THandle;
      path : string;
    begin
      //写入函数
      path := ExtractFilePath(Application.ExeName)+'log';
      if not DirectoryExists(path) then
      ForceDirectories(path);  if   not   FileExists(sFileName)   then
      begin
        if not FileExists(sFileName) then //如果文件不存在
        begin
         h:=CreateFile(pchar(sFileName),3,5,nil,CREATE_ALWAYS,FILE_ATTRIBUTE_ARCHIVE,0);
         Closehandle(h);
        end;
      end;  assignfile(txtfile,sFileName);
      Reset(txtfile);
      Append(txtfile);
      writeln(txtfile,sText);
      closefile(txtfile);
    end;