大概写了一个,将就着用吧. <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> exit; <br> ASize := AStream.Size; <br> if (Index >= ASize) or (Count = 0) then <br> exit; <br> if (Index + Count) >= ASize then <br> begin <br> AStream.Size := Index; <br> exit; <br> end <br> else begin <br> SavedPos := AStream.Position; <br> try <br> AStream.Seek(Index + Count, soFromBeginning); <br> BufferStream := TMemoryStream.Create; <br> try <br> ASize := ASize - (Index + Count); <br> BufferStream.SetSize(ASize); <br> BufferStream.Seek(0, soFromBeginning); <br> BufferStream.CopyFrom(AStream, ASize); <br> AStream.Size := Index + ASize; <br> AStream.Seek(Index, soFromBeginning); <br> AStream.Write(BufferStream.Memory^, ASize); <br> finally <br> BufferStream.Free; <br> end; <br> finally <br> AStream.Position := SavedPos; <br> 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); //从 Position 为 10(第 11 个字节)起删除 5 bytes.