Created
April 4, 2021 21:30
-
-
Save Pasquina/df816a52aba9d006a31c7a191a9e0664 to your computer and use it in GitHub Desktop.
Sample FileStream writing TMemo lines
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ Saving from TMemo.Lines does not honor the TrailingLineBreak option of | |
TStrings. } | |
procedure TfSavingMemoLines.aSaveLinesExecute(Sender: TObject); | |
var | |
LMode: Word; // in case we need to create the file | |
LFileStream: TFileStream; // handle the writing | |
begin | |
if not FileExists(LogFileName) then // test for file exists | |
LMode := fmCreate // not present need to create | |
else | |
LMode := fmOpenReadWrite; // present need to append | |
LFileStream := TFileStream.Create(LogFileName, LMode or fmShareDenyWrite); // open log file | |
try | |
LFileStream.Seek(0, soFromEnd); // make sure at the end of the existing file | |
mMain.Lines.SaveToStream(LFileStream, TEncoding.UTF8); // add the lines to the end | |
finally | |
LFileStream.Free; // return resources | |
end; | |
end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example of using TFileStream to save lines from a TMemo component. This method fails to honor the TrailingLineBreak option.