Page 2 of 2
Posted: Wed Apr 16, 2008 4:53 am
by Sergey Tkachenko
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.
Posted: Wed Apr 16, 2008 6:22 am
by Cosmin3
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):
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'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...
Posted: Wed Apr 16, 2008 7:15 am
by Sergey Tkachenko
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.
Posted: Wed Apr 16, 2008 7:16 am
by Sergey Tkachenko
In your code, I do not understand the statement
Code: Select all
if i = srvEditor.RichViewEdit.ItemCount - 1 then ...
Why do you need to process the last item specially? This item is not necessary starts a paragraph.
Posted: Wed Apr 16, 2008 7:38 am
by Cosmin3
It's not 100% necessary but I used it to avoid adding a #13#10 at the end. It can be removed if you want and set first cycle to ItemCount - 1.
Later edit: I have solved the problem. Thank you for all your patience...
Posted: Thu Apr 17, 2008 9:58 pm
by Pieter Zijlstra
Would you be so kind to tell us what it was?
Posted: Fri Apr 18, 2008 5:45 pm
by Cosmin3
I'm not so good of explaining in English but if you want I will show you my code...