Protected Paragraph Help...

General TRichView support forum. Please post your questions here
Post Reply
jnap
Posts: 31
Joined: Sat Sep 30, 2006 6:23 pm

Protected Paragraph Help...

Post by jnap »

Hi,

in my program at OnFormCreate I add a little notice displayed in Red with a red border surround.

I add it like this:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
begin
  rve.Clear;
  rve.AddTextNL('My Program Name - Trial Version',1,1,0);
  // Create two new lines...
  rve.AddNL('',0,0);
  rve.AddNL('',0,0);
  rve.Format;
  // Now I need to position cursor (caret) at the second added new line
end;
The paragraph is centered and Read Only.

I now need to be able to set the cursor position for the user to begin typing to the last AddNL('',0,0);

How can I do this?

Also I have a problem that if the user presses Delete the cursor will end up at the end of the Protected - Read Only paragraph and then cannot press enter any more!

How can I please avoid this little problem?

Many thanks

jnap
jnap
Posts: 31
Joined: Sat Sep 30, 2006 6:23 pm

Post by jnap »

I have solved the first problem by calling the below procedure:

Code: Select all

procedure GoToParagraph(rve: TCustomRichViewEdit; ParagraphIndex: Integer); 
var i: Integer; 
begin 
  for i := 0 to rve.ItemCount-1 do begin 
    if rve.IsParaStart(i) then 
      dec(ParagraphIndex); 
    if ParagraphIndex<0 then begin 
      rve.SetSelectionBounds(i, rve.GetOffsBeforeItem(i), i, rve.GetOffsBeforeItem(i)); 
      rve.Invalidate; 
      exit; 
    end; 
  end; 
end;
But now I need advice on how to prevent the user pressing Delete and cursor is now at the end of the Protected - Read Only paragraph?

User can no longer type anything or press Enter. Is there a way somehow to prevent this from happening? Any ideas are very welcome!

Many thanks

jnap
Sergey Tkachenko
Site Admin
Posts: 17310
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Sorry, I do not understand the question.
When the caret is in read-only paragraph (rvpaoReadOnly in Options), the user cannot do any editing operations - no typing, no delete, no backspace.
The only allowed editing procedure is pressing Enter at the beginning and at the end of this paragraph. If you want to disallow Enter as well, include rvpaoDoNotWantReturns in the paragraph style Options too.
But I do not understand what's wrong with Delete.
jnap
Posts: 31
Joined: Sat Sep 30, 2006 6:23 pm

Post by jnap »

Hi Sergey,

I am sorry, I should have explained my problem a little better.

I have made a paragraph Read Only that I need displayed at the very Top of the document. I need this to stay in this position permanently.

After I have added the Read Only paragraph, I add two blank lines using:

Code: Select all

  rve.AddNL('',0,0); 
  rve.AddNL('',0,0); 
  rve.Format;
Then I set the cursor position to the last added line using the GoToParagraph procedure so that the user can begin creating the document.

I am in a catch 22 situation because now if I add rvpaoDoNotWantReturns
and the user presses delete they end up in the readonly paragraph and from then on cannot press Enter!

If I do not add rvpaoDoNotWantReturns then the user can go to the start of the readonly paragraph and keep pressing Enter untill my Trial Version notice is out of view. (Which I do not want).

So in essence, I need to keep the readonly paragraph at the top of the page using rvpaoDoNotWantReturns but I know the user will try to delete the Trial Text by pressing Delete and then become stuck in this paragraph!

I hope you understand what I mean, I could always send you the source if you do not.

Many thanks

jnap
jnap
Posts: 31
Joined: Sat Sep 30, 2006 6:23 pm

Post by jnap »

Hi Sergey,

I am sorry, I should have explained my problem a little better.

I have made a paragraph Read Only that I need displayed at the very Top of the document. I need this to stay in this position permanently.

After I have added the Read Only paragraph, I add two blank lines using:

Code: Select all

  rve.AddNL('',0,0); 
  rve.AddNL('',0,0); 
  rve.Format;
Then I set the cursor position to the last added line using the GoToParagraph procedure so that the user can begin creating the document.

I am in a catch 22 situation because now if I add rvpaoDoNotWantReturns
and the user presses delete they end up in the readonly paragraph and from then on cannot press Enter!

If I do not add rvpaoDoNotWantReturns then the user can go to the start of the readonly paragraph and keep pressing Enter untill my Trial Version notice is out of view. (Which I do not want).

So in essence, I need to keep the readonly paragraph at the top of the page using rvpaoDoNotWantReturns but I know the user will try to delete the Trial Text by pressing Delete and then become stuck in this paragraph!

I hope you understand what I mean, I could always send you the source if you do not.

Many thanks

jnap
jnap
Posts: 31
Joined: Sat Sep 30, 2006 6:23 pm

Protected Paragraph Help... (Solved)

Post by jnap »

I have now resolved this by adding another protected paragraph so the code looks like this:

Code: Select all

  rve.Clear;
  rve.AddTextNL('Program Name - Trial Version',1,1,0);
  rve.AddTextNL('',1,2,0);
  rve.AddNL('',0,0);
  rve.Format;
  GoToParagraph(rve, 2);
The only problem I get now is that during Select All the protected paragraph also gets selected making a delete operation impossible. Is there anyway to make the protected paragraph UnSelectable?

Many thanks

jnap
Sergey Tkachenko
Site Admin
Posts: 17310
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Well, really, if the user deletes all editable content, the caret will be in the first paragraph, and he/she will not be able to edit.

Try to use text protection instead of paragraph protection.
Include the following options in the Protection property of text style:
rvprStyleProtect, rvprModifyProtect, rvprDeleteProtect, rvprDoNotAutoSwitch, rvprStickToTop.
jnap
Posts: 31
Joined: Sat Sep 30, 2006 6:23 pm

Post by jnap »

I have just tried with Protected Text using all the settings you suggest but then the problem returns that the user can just press Enter at the start of the protected text and move it down out of view.

I have switched StickToTop to True but this has no effect.

Also with Text Protection the problem if Select All is pressed then nothing can be deleted as everything is selected.

I think I should return to using the Protected Paragraphs and try doing something with SetSelectionBounds?

If I do it this way there should be a way to prevent selecting the first 2 lines but select everything else in the document? Is SetSelectionBounds the right way to go?

Thanks for all your help

jnap
Sergey Tkachenko
Site Admin
Posts: 17310
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

If you can press Enter at the beginning of text with "stick to top" protection, it is a bug, I'll fix it in the next update.

I thought that you want to disallow deletion of this paragraph. If not, exclude rvprDeleteProtect.
Sergey Tkachenko
Site Admin
Posts: 17310
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Confirmed: "sticking" options did not protect from Enter.
I fixed it, will be uploaded with the next update.
Post Reply