Board index » delphi » TRichEdit problem with protected text

TRichEdit problem with protected text

Hi I'm writing an app where I need to be able to allow the user to be able
to enter text into a field, without being able to change what was
previously there.

To do this I'm loading a TRichEdit with the previous text, setting it
protected then allowing the user to edit, saving the finished results
then un-protecting and calling the clear method for the TRitchEdit.

This works fine, the first time through but on subsiquent edits the
protected part of the previous data is still there, apparently having
survived the clear operation :( Is this a known bug and is there a work
round for it ?

The procedure I'm using to do the setting/unsetting of protected is :-

Description is a TRichEdit.

PROCEDURE TDataForm.SetEditProtect(Protect      : BOOLEAN);

BEGIN;
  Description.SelStart:=0;
  Description.SelLength:=Length(Description.Text);
  Description.SelAttributes.Protected:=Protect;
  Description.SelStart:=Length(Description.Text)-1;
  Description.SelLength:=0;
END;

So what I'm doing is (psudo code not Pascal !):-

PROCEDURE OnButton1Click;

begin;
  LoadOldText into Description
  SetEditProtect(True)
  Edit text
  SaveNewText from description
  SetEditProtect(False)
  Description.Clear
end;

Thing is next time I click the button the old protected text has not been
cleared :(

Thanks for any help.

 

Re:TRichEdit problem with protected text


Quote
"Phill Harvey-Smith" <ph...@dna.warwick.ac.uk> wrote in message

news:Xns9144706AA7A4Ephilldnawarwickacuk@137.205.128.11...

Quote

> Hi I'm writing an app where I need to be able to allow the user to be able
> to enter text into a field, without being able to change what was
> previously there.

> To do this I'm loading a TRichEdit with the previous text, setting it
> protected then allowing the user to edit, saving the finished results
> then un-protecting and calling the clear method for the TRitchEdit.

> This works fine, the first time through but on subsiquent edits the
> protected part of the previous data is still there, apparently having
> survived the clear operation :( Is this a known bug and is there a work
> round for it ?

> The procedure I'm using to do the setting/unsetting of protected is :-

> Description is a TRichEdit.

> PROCEDURE TDataForm.SetEditProtect(Protect      : BOOLEAN);

> BEGIN;
>   Description.SelStart:=0;
>   Description.SelLength:=Length(Description.Text);
>   Description.SelAttributes.Protected:=Protect;

This could be simplified with

Description.SelectAll;
Description.SelAttributes.Protected := Protect;

I'm not sure if it will solve the problem, but I do know that one cannot
reliably work with counting characters in the Text attribute to judge
length.

Other Threads