Sorry, I do not understand what's wrong.
In your example:
Item[0] = 'LETHAL' IsFromNewLine = True, because the document starts from a new line, IsFromNewLine(0) is always true.
Item[1] = character IsFromNewLine = False, because the character contunues the same paragraph as the previous item.
Item[2] = ' WEAPON 4.' IsFromNewLine = False, because this text continues the same paragraph as the previous item.
Item[3] = 'Riggs, are you...' IsFromNewLine = True, because this text starts a new paragraph.
When exporting to text, of all these items, #13#10 must be inserted only before the 3rd item.
loading a Unicode file line by line
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
I don't understand why a text line is loosing NewLine at the end by inserting a character in it. But visual in ScalRichView is still a text line.
And I said that this is happenning on all items (lines) not only at the first.
The problem is that I load also subtitles: text is loaded in ScaleRichView and frames/times in an integer array.
The lines from the original subtitle are composed by one or more items.
Until now I used to synchronize lines from RichVieEdit with that array using IsFromNewLine and was working well.
The code looks like that (for a Unicode SubRip subtitle):
I'm saving lines instead of all text at once because I noticed it's faster this way (it takes time to append all the lines in a string).
I don't know how to implement your code but still keeping the synchronization between text and that array...
And I said that this is happenning on all items (lines) not only at the first.
The problem is that I load also subtitles: text is loaded in ScaleRichView and frames/times in an integer array.
The lines from the original subtitle are composed by one or more items.
Until now I used to synchronize lines from RichVieEdit with that array using IsFromNewLine and was working well.
The code looks like that (for a Unicode SubRip subtitle):
Code: Select all
try
begin
tf := TFileStream.Create(FileName, fmCreate or fmShareExclusive);
ws := #65279;
if tf.Write(Pointer(ws)^, 2) <> 2 then
i := -1
else
if srvEditor.RichViewEdit.ItemCount > 0 then
begin
ws := '';
SubCnt := -1;
for i := 0 to srvEditor.RichViewEdit.ItemCount - 2 do
begin
if not srvEditor.RichViewEdit.IsFromNewLine(i) then
ws := ws + srvEditor.RichViewEdit.GetItemTextW(i)
else
begin
Inc(SubCnt);
ws := IntToStr(SubCnt + 1) + #13#10 +
FormatDateTime('hh:nn:ss' + Char(44 + (SrtType - 1) * 2) + 'zzz', 1.0 * SubTimes[SubCnt][1] / 86400000) +
' --> ' +
FormatDateTime('hh:nn:ss' + Char(44 + (SrtType - 1) * 2) + 'zzz', 1.0 * SubTimes[SubCnt][2] / 86400000) +
#13#10 + StringReplace(ws + srvEditor.RichViewEdit.GetItemTextW(i), '|', #13#10, [rfReplaceAll]) + #13#10#13#10;
if tf.Write(Pointer(ws)^, 2 * Length(ws)) <> 2 * Length(ws) then
Break;
ws := '';
end;
end;
if i = srvEditor.RichViewEdit.ItemCount - 1 then
begin
Inc(SubCnt);
ws := IntToStr(SubCnt + 1) + #13#10 +
FormatDateTime('hh:nn:ss' + Char(44 + (SrtType - 1) * 2) + 'zzz', 1.0 * SubTimes[SubCnt][1] / 86400000) +
' --> ' +
FormatDateTime('hh:nn:ss' + Char(44 + (SrtType - 1) * 2) + 'zzz', 1.0 * SubTimes[SubCnt][2] / 86400000) +
#13#10 + StringReplace(ws + srvEditor.RichViewEdit.GetItemTextW(i), '|', #13#10, [rfReplaceAll]) + #13#10;
if tf.Write(Pointer(ws)^, 2 * Length(ws)) = 2 * Length(ws) then
Inc(i);
end;
end
else
i := 1;
tf.Free;
Result := i >= srvEditor.RichViewEdit.ItemCount;
end;
finally
ws := '';
end;
if not Result then
CustomMessage('Write error', MB_ICONERROR or MB_OK);
I don't know how to implement your code but still keeping the synchronization between text and that array...
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Sorry, what do you think IsFromNewLine means? Probably, you misunderstand it, and so there is a confusion.
Actually, it means "this item starts a paragraph" (or a line inside paragraph, added with Shift+Enter).
In your example, there are 2 paragraphs, so there are must be only 2 items having IsFromNewLine = True.
In the first paragraph ("LETHAL", character, "WEAPON 4"), the first paragraph item is "LETHAL", and it has IsFromNewLine=True.
In the second paragraph, there is only one item, and it has IsFromNewLine=True.
Actually, it means "this item starts a paragraph" (or a line inside paragraph, added with Shift+Enter).
In your example, there are 2 paragraphs, so there are must be only 2 items having IsFromNewLine = True.
In the first paragraph ("LETHAL", character, "WEAPON 4"), the first paragraph item is "LETHAL", and it has IsFromNewLine=True.
In the second paragraph, there is only one item, and it has IsFromNewLine=True.
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
In your code, I do not understand the statement
Why do you need to process the last item specially? This item is not necessary starts a paragraph.
Code: Select all
if i = srvEditor.RichViewEdit.ItemCount - 1 then ...
-
- Posts: 42
- Joined: Sat Oct 08, 2005 3:56 pm
- Location: The Netherlands
- Contact: