SynEdit currently does not add line endings to SynEdit.Lines[].
It does if you get the entire SynEdit.Text.
However if you do
SynEdit.Lines[n]:='abc'+LineEnding
the lineending may be stored, and will be in the results. (SynEdit will ignore it when working with the text)
So it all depends, if you get any line ends in there (no idea what LoadFormFile does)
- loop over SynEdit.Lines[]
- if need remove line ends
- sum up the Utf8Length
Note, if you switched on remove trailing spaces, the trailing spaces on the current line may not be in the result (may depend on the settings, but usually they are not)
looping over SynEdit.Lines[] is more efficient than using SynEdit.Text.
SynEdit.Text must first build a new string with all the lines in it.
len:=0;
for i := 0 to syn.lines.count - 1 do begin
s := syn.lines[i];
len:= len + utf8length(s); // includes line end
j := length(s)-1; // normal byte len
while (j>0) and s[j] in [#10, #13] do begin
dec(j);
dec(len);
end;
end;