Delphi 用文件流读取文本文件字符串的方法


本文整理自网络,侵删。

 
procedure TForm23.Button4Click(Sender: TObject);
var
pstr:Pchar;
mestr,Str1:string;
FS:TFilestream;
meint,PoStr,I,LenStr:integer;
Fpos:Int64;
TT,IsDay:Boolean;
Liststr:TStringList;
begin
  if not Self.OpenDialog1.Execute then Exit;
  FS:=TFileStream.Create(Self.OpenDialog1.FileName,fmOpenRead);
  meint:=1024;
  getmem(pstr,meint);//申请字符指针内存
  TT :=False;
  I:=0;
  Liststr :=TStringList.Create;
  try
    while not TT do
    begin
      Fpos:=I*meint;
      FS.Position:=Fpos;
      fs.Readbuffer(pstr^,meint);
      if True then
       
      mestr:=pstr;
      SetLength(mestr,meint);
      Liststr.Text:=mestr;
      if i=0 then Self.Memo1.Text:=Liststr.Text;
      Self.Edit1.Text :=IntToStr(Liststr.Count);
      i:=i+1;
      if i>2 then TT :=True;
    end;
  finally
    freemem(Pstr);//释放内存
    FS.Free;//释放流
    Liststr.Free;
  end;
end;

相关阅读 >>

Delphi listview高速添加数据

Delphi 简单字符串截取函数

Delphi中单独编译pas生成dcu文件

Delphi 蓝牙连接打印机演示

Delphi中动态加载treeview信息

Delphi制作移动文字、图片

Delphi windows 编程[15] - 菜单消息: wm_command

Delphi clipboard 截图后将图片数据复制到剪贴板

Delphi 纯window系统api实现的ssl客户端

Delphi listboxadditems() 不重复添加edit1

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...