一个很简单的问题。大家进来看看啊!(50分)

  • 主题发起人 主题发起人 6713829
  • 开始时间 开始时间
6

6713829

Unregistered / Unconfirmed
GUEST, unregistred user!
TFileStream的函数<br>Seek:此方法实现流中读取指针的移动。<br><br>谁能详细的告诉我一下啊,最好有个例子!<br>希望大侠都帮帮我!!!
 
大概写了一个,将就着用吧. <br>//AStream 进行删除操作的 TStream 实例 <br>//从 Stream 中 Position 为 Index 处开始删除 Count 个字节.注意 Index 从 0 开始. <br>procedure StreamDelete(AStream: TStream; Index: Longint; Count: Longint); <br>var <br> SavedPos: Longint; <br> ASize: Longint; <br> BufferStream: TMemoryStream; <br>begin <br> if not Assigned(AStream) then <br> &nbsp; exit; <br> ASize := AStream.Size; <br> if (Index &gt;= ASize) or (Count = 0) then <br> &nbsp; exit; <br> if (Index + Count) &gt;= ASize &nbsp;then <br> begin <br> &nbsp; AStream.Size := Index; <br> &nbsp; exit; <br> end <br> else begin <br> &nbsp; SavedPos := AStream.Position; <br> &nbsp; try <br> &nbsp; &nbsp; AStream.Seek(Index + Count, soFromBeginning); <br> &nbsp; &nbsp; BufferStream := TMemoryStream.Create; <br> &nbsp; &nbsp; try <br> &nbsp; &nbsp; &nbsp; ASize := ASize - (Index + Count); <br> &nbsp; &nbsp; &nbsp; BufferStream.SetSize(ASize); <br> &nbsp; &nbsp; &nbsp; BufferStream.Seek(0, soFromBeginning); <br> &nbsp; &nbsp; &nbsp; BufferStream.CopyFrom(AStream, ASize); <br> &nbsp; &nbsp; &nbsp; AStream.Size := Index + ASize; <br> &nbsp; &nbsp; &nbsp; AStream.Seek(Index, soFromBeginning); <br> &nbsp; &nbsp; &nbsp; AStream.Write(BufferStream.Memory^, ASize); <br> &nbsp; &nbsp; finally <br> &nbsp; &nbsp; &nbsp; BufferStream.Free; <br> &nbsp; &nbsp; end; <br> &nbsp; finally <br> &nbsp; &nbsp; AStream.Position := SavedPos; <br> &nbsp; end; <br> end; <br>end; <br>用法: <br>var <br> FileStream: TFileStream; <br>... <br> //对 TFileStream, OpenMode 必须为 fmOpenReadWrite,保证可读写. <br> FileStream := TFileStream.Create('c:/aaa.txt', fmOpenReadWrite); <br> StreamDelete(FileStream, 10, 5); &nbsp;//从 Position 为 10(第 11 个字节)起删除 5 bytes.
 
大哥,还是不知道啊,<br>你这个BufferStream.Seek(0, soFromBeginning);<br>在里面起什么作用啊?
 
你可以找一下,网上有个专门介绍Delphi流操作的电子书,将的还是比较详细,还有相应的例子,我这有一个,如果你想要的话把你的Email留一下,我给你发过去。
 
eonzhang:<br> &nbsp;我想要一份来学习一下,可以发给我吗?shenlangw@163.com<br> &nbsp;谢谢!
 
Seek函数有两个参数。<br>联机帮助中将的很清楚!!<br>第一个参数是文件类型。可是Delphi5开发人员指南里第一个参数是整型的。<br>第二个参数表示从文件头起的位移。<br>(文件句柄,偏移量,起始位置)。
 
Delphi流操作的电子书,我已经有了,但是写的有点复杂看不懂。<br>谢谢,也解决!
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
851
DelphiTeacher的专栏
D
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
后退
顶部