I'm doing an operation in which I'm adding a series of small TRichView documents, stored in RVF, to the end of an existing document. Each of these small documents is actually a comment, so I need to create a numbered list, adding a list marker before each comment. This seems to be half-working; all of the small documents are added correctly, but the list numbers don't show up. Here's what I have:
if CommList.Count > 0 then
begin
//Add a numbered list style to the RVS, so we can use it for the comment list
ListInfo := tmpRVS.ListStyles.Add;
ListNo := tmpRVS.ListStyles.Count-1;
ListLevel := ListInfo.Levels.Add;
LevelNo := ListInfo.Levels.Count-1;
with ListLevel do
begin
ListType := rvlstDecimal;
Font.Assign(tmpRVS.TextStyles[0]);
FirstIndent := 0;
LeftIndent := 24;
FormatString := '%1.';
FormatStringW := WideString('%1.');
StartFrom := 1;
MarkerIndent := 12;
end;
for i := 1 to CommList.Count do
begin
//Get the comment rvf
strTemp := GetCommentRVFFromCommNum(i);
StrStream := TStringStream.Create(strTemp);;
try
//Add the comment to the end of the document
StrStream.Position := 0;
//Add a list item
tmpRVE.SetListMarkerInfo(-1, ListNo, LevelNo, 0, 0, False);
tmpRVE.AddNLWTag('', -1, -1, 0);
SetCursorToEnd;
tmpRVE.InsertRVFFromStreamEd(StrStream);
tmpRVE.Format;
finally
FreeAndNil(StrStream);
end;
end;
SetCursorToEnd is a simple inline function that does this:
procedure SetCursorToEnd;
begin
//Format first, just in case
tmpRVE.Format;
//Set the cursor to the end of the document
tmpRVE.SetSelectionBounds(tmpRVE.ItemCount-1,
tmpRVE.GetOffsAfterItem(tmpRVE.ItemCount-1), tmpRVE.ItemCount-1,
tmpRVE.GetOffsAfterItem(tmpRVE.ItemCount-1));
end;
If I don't use that, the comments are all added at the beginning of the document. The result, when saved out to RTF, doesn't show any list numbers. I must be doing something wrong, but I can't figure it out. Any ideas?
All help appreciated,
Martin
Adding numbered comments from RVF
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
This value for ListLevel.FormatString is incorrect.
The correct value for Levels[0].FormatString is '%0:s.' (or simply '%s.').
Besides, I suggest to change the cycle to:
My version is more efficient, but has limitations: the first item in comment must not be a table, break or list marker.
Your version is more universal, but less efficient. But you call Format even twice: (1) in SetCursorToEnd (2) before "finally".
The first call is necessary, because it is after viewer-style AddNLWTag and before calling editing-style InsertRVFFromStreamEd.
The second call is not needed.
PS: You save RVF in TStringStream. But RVF cannot be saved to TStringStream unless rvfoSaveBinary is excluded from RVFOptions.
The correct value for Levels[0].FormatString is '%0:s.' (or simply '%s.').
Besides, I suggest to change the cycle to:
Code: Select all
for i := 1 to CommList.Count do
begin
//Get the comment rvf
strTemp := GetCommentRVFFromCommNum(i);
StrStream := TStringStream.Create(strTemp);
try
//Add the comment to the end of the document
StrStream.Position := 0;
//Add a list item
tmpRVE.SetListMarkerInfo(-1, ListNo, LevelNo, 0, 0, False);
ItemCount := tmpRVE.ItemCount;
tmpRVE.AppendRVFFromStreamEd(StrStream, -1);
if ItemCount = tmpRVE.ItemCount then
tmpRVE.AddNLWTag('', -1, -1, 0);
finally
FreeAndNil(StrStream);
end;
end;
tmpRVE.Format;
Your version is more universal, but less efficient. But you call Format even twice: (1) in SetCursorToEnd (2) before "finally".
The first call is necessary, because it is after viewer-style AddNLWTag and before calling editing-style InsertRVFFromStreamEd.
The second call is not needed.
PS: You save RVF in TStringStream. But RVF cannot be saved to TStringStream unless rvfoSaveBinary is excluded from RVFOptions.
-
- Posts: 131
- Joined: Mon Aug 29, 2005 12:03 pm
Thanks Sergey -- it was the FormatString that was the problem.
I can't be sure that the first item in each comment won't be a table, so I have to stick with my less efficient version. The only problem that remains is the issue of embedded lists inside the comments. They're not indented enough, because their style settings are coming from their standalone document. I guess I need to iterate through all the items in each comment, looking for lists, and change their list level.
Cheers,
Martin
I can't be sure that the first item in each comment won't be a table, so I have to stick with my less efficient version. The only problem that remains is the issue of embedded lists inside the comments. They're not indented enough, because their style settings are coming from their standalone document. I guess I need to iterate through all the items in each comment, looking for lists, and change their list level.
Cheers,
Martin