Delphi. SynEdit - load last 500 KB of file
Please suggest me something.
How can I load into开发者_运维问答 UniSynEdit/SynEdit last 500 KB of file if it is more then 500 KB?
Thanks!!!
One option you have is to copy the last 500 KB of the file into a temporary file and then ask synEdit to process the temporary file.
Create a TFileStream
and seek to the position you want to load from, and then pass the stream to the edit control. It should load from the current position.
var
stream: TStream;
begin
stream := TFileStream.Create(filename, fmOpenRead);
try
stream.Seek(-500 * 1024, soEnd);
edit.Lines.LoadFromStream(stream);
finally
stream.Free;
end;
end;
Beware that if the file is encoded as UTF-8 or something else that uses a variable number of bytes per character, it isn't safe to jump to arbitrary positions in the file. You might jump to a byte that represents the second half of a two-byte sequence, and then all the subsequent characters you read could be interpreted incorrectly. ANSI and UTF-16 files don't have that danger.
精彩评论