Page 1 of 1

How to protect paragraph against deletion?

Posted: Thu Feb 07, 2008 3:24 pm
by duzenko
I have several rows with paired text, for example:

Code: Select all

1
one
2
two
I must allow user to delete e.g. text "one" but not to delete paragraph, so that an empty paragraph should remain. How to do that?

Current protection that I use

Code: Select all

  FNativeParaStyleId := Style.ParaStyles.Count;
  Style.ParaStyles.Add.Background.Color := clInactiveCaptionText;
  FNativeTextStyleId := Style.TextStyles.Count;
  Style.TextStyles.Add.Protection := [rvprDeleteProtect, rvprModifyProtect, rvprConcateProtect];

Posted: Thu Feb 07, 2008 6:35 pm
by Sergey Tkachenko
rvprModifyProtect does not allow editing text, so probably you should remove it.
rvprDeleteProtect does not allow deleting item (at least one character must remain), so this is probably what you need.
Also consider using rvprParaStartProtect.

Posted: Fri Feb 08, 2008 8:44 am
by duzenko
You did not understand.

Current code is

Code: Select all

  FNativeTextStyleId := Style.TextStyles.Count;
  Style.TextStyles.Add.Protection := [rvprDeleteProtect, rvprModifyProtect];
  FTranslationTextStyleId := Style.TextStyles.Count;
  Style.TextStyles.Add.Protection := [rvprParaStartProtect];
FNativeTextStyleId is for odd lines. They are should not be edited at all.

FTranslationTextStyleId is for even lines. They will be edited but should not be erased as paragraphs. In the above-stated example, user should be able to remove text "one" but not the whole line. I.e. empty line should remain.

Now I can delete the line by Backspace key, so that "1" and "2" lines appear close by, without an empty line between them.

Posted: Fri Feb 08, 2008 3:58 pm
by Sergey Tkachenko
It's not possible to implement exactly what you want. You can include DeleteProtect without ModifyProtect, it's almost what you need, but... It does not allow the last character of item to be deleted, i.e. it does not allow to create empty item from it.
May be protection allowing making empty items will be introduced in new version, but not now.

May be you can consider using tables?

Posted: Fri Feb 08, 2008 3:59 pm
by duzenko
Sergey Tkachenko wrote:May be you can consider using tables?
If this is the only way :( ...

Posted: Tue Feb 12, 2008 12:28 pm
by duzenko
I filled a table cells with text. How can I protect text in some cells against editing?

Posted: Tue Feb 12, 2008 5:58 pm
by Sergey Tkachenko
a) Using paragraph and/or text protection (Options property of paragraph style, Protection property of text style)
or
b) Using table.OnCellEditing event

Posted: Wed Feb 13, 2008 9:54 am
by duzenko
This is ready. Now I need to select certain text in a certain cell, for example, from 10th to 20th characters in the cell[3, 1]. I guess I should use SetSelectionBounds function. But what parameters do I have to pass into it in my case?

Code: Select all

  procedure AddRow(List: TTntStringList; index, ParaStyleId, TextStyleId: Integer);
  var
    tmp: WideString;
  begin
    if List.Count > index then
      tmp := List[index]
    else
      tmp := '';
    if RowCount > TableInfo.RowCount then
      TableInfo.InsertRows(TableInfo.RowCount, RowCount - TableInfo.RowCount, -1);
    with TableInfo.Cells[RowCount - 1, 0] do begin
      DeleteItems(0, ItemCount);
      AddNLWTag(tmp, TextStyleId, ParaStyleId, 0);
      if Odd(RowCount) then
        Color := $DDDDDD;
    end;
    TableInfo.EditCell(RowCount - 1, 0);
    TCustomRVFormattedData(TableInfo.Cells[RowCount - 1, 0].Edit).SelectAll;
    Inc(RowCount);
  end;
On EditCell call I get error

---------------------------
Debugger Exception Notification
---------------------------
Project SE_sample.exe raised exception class EListError with message 'List index out of bounds (-1)'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------

Posted: Thu Feb 14, 2008 9:42 am
by duzenko
Would anyone help me with that?

Posted: Thu Feb 14, 2008 1:06 pm
by Sergey Tkachenko
You cannot select or edit in unformatted documents.
So you cannot call EditCell and SelectAll until you call Format.

Posted: Thu Feb 14, 2008 1:08 pm
by duzenko
It's interesting, especially that help topic "Selection in Table" says nothing about it.

Posted: Thu Feb 14, 2008 1:20 pm
by Sergey Tkachenko
Well, I added the remark about formatting in all topics about TRichView/TRichViewEdit methods working with selection (including SelectAll), but I forgot to do it in table topics.
I'll fix the help file in the next update.

Posted: Thu Feb 14, 2008 1:24 pm
by duzenko
I added the Format function call. This allowed me to get rid of the exception, but now the RichViewEdit gets focused on the parent form during the building of documents.

This is a cosmetic thing but is important for us.

How could I avoid self-focusing of the component?

Posted: Thu Feb 14, 2008 1:44 pm
by Sergey Tkachenko
Answered by e-mail