我正在尝试使用Delphi中的TFileStream创建一个指针列表来存储每行开头的指针。 我已经通过以下链接TFileStream_Methods来检查所有方法。但是我找不到任何有用的东西,我可以找到每条线的起始位置的指针值。
我试过以下:
procedure TForm4.Button3Click(Sender: TObject);
var
InStream: TFileStream;
OutStream: TMemoryStream;
Writer: TStreamWriter;
Buffer: TArray<Byte>;
Encoding: TEncoding;
BOMValue: Integer;
FileName: string;
Temp: string;
TempInt: Integer;
//Buffer2: Buffer;
begin
try
//SetLength(Buffer, 8);
//InStream.Read(Buffer, Length(Buffer));
finally
//InStream.Free;
end;
try
SetLength(Buffer, 8);
//InStream.Read(Buffer, Length(Buffer));
finally
//InStream.Free;
end;
Encoding := nil;
BOMValue := TEncoding.GetBufferEncoding(Buffer, Encoding, TEncoding.ASCII);
OutStream := TMemoryStream.Create;
Writer := TStreamWriter.Create(OutStream, Encoding);
FileName := 'C:\bugs\Rnd\mainfile.cpp';
try
InStream := TFileStream.Create(FileName, fmOpenRead);
InStream.Seek(BOMValue, soCurrent);
Temp := InStream.ToString();
TempInt := InStream.InstanceSize();
OutStream.CopyFrom(InStream, 10);
InStream.Seek(10, soCurrent);
Writer.Write('abc');
OutStream.CopyFrom(InStream,60);
InStream.Free;
OutStream.SaveToFile(FileName);
finally
//InStream.Free;
Writer.Free;
OutStream.Free;
end;
end;
我正在使用InStream
,我如何逐个字符地读取它(甚至多字节字符)并且可以计算每行的第一个位置的指针。
过去2天我一直在尝试,但没有任何运气。任何帮助都会受到高度赞赏。