您好,欢迎来到[编程问答]网站首页   源码下载   电子书籍   软件下载   专题
当前位置:首页 >> 编程问答 >> Delphi >> delphi建立txt,通过文本框来写入数据帮帮忙把

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

来源:网络整理     时间:2016/7/2 23:50:50     关键词:

关于网友提出的“ delphi建立txt,通过文本框来写入数据帮帮忙把”问题疑问,本网通过在网上对“ delphi建立txt,通过文本框来写入数据帮帮忙把”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:

问题: delphi建立txt,通过文本框来写入数据帮帮忙把
描述:

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


解决方案1:

你是想要把文本框里的数据保存到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;

解决方案2:

使用TStringLIst加载、保存

解决方案3:

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

解决方案4:

LoadFromFile...

解决方案5:

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

解决方案6:

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;
明白了吗?

解决方案7:

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;


以上介绍了“ delphi建立txt,通过文本框来写入数据帮帮忙把”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/2226144.html

相关图片

相关文章