trichview.com

trichview.support




Re: how to select characters from cursor position


Return to index


Author

Message

Sergey Tkachenko

Posted: 02/25/2004 0:32:11


This code (OnKeyPress event) replaces 'ka' typed by user with 'd'.

Replacement occurs when user types the last character ('a').


procedure TForm3.RichViewEdit1KeyPress(Sender: TObject; var Key: Char);

var rve: TCustomRichViewEdit;

    ItemNo, Offs, Len: Integer;

    s: String;

const

   ReplaceFrom = 'ka';

   ReplaceTo   = 'd';

begin

  rve := RichViewEdit1.TopLevelEditor;

  ItemNo := rve.CurItemNo;

  Offs := rve.OffsetInCurItem;

  if rve.GetItemStyle(ItemNo)<0 then

    exit;

  Len := Length(ReplaceFrom)-1;

  if Offs<=Len then

    exit;

  s := rve.GetItemTextA(ItemNo);

  s := Copy(s, Offs-Len, Len);

  if s+Key=ReplaceFrom then begin

    rve.SetSelectionBounds(ItemNo, Offs-Len, ItemNo, Offs);

    rve.InsertText(ReplaceTo);

    Key := #0;

  end;

end;


There was a similar example in this newsgroup (thread "Autocompletion"). In

that example, replacement occurs when the user presses a space character

after the word which must be replaced.


>

> My requirement is at the time of rve keypress if some character

combinations

> are comming, I want to replace it with some other character. (eg. whenever

> the user press 'ka' I want to replace with 'd') It is for implementing

Malayalam

> (an Indian regional language) in richview. I am doing the experiment with

> the trial edition of richview. Once I will able to implement this I want

> to purchase the component.

>

> thanks

>

> "Sergey Tkachenko" <[email protected]> wrote:

> >I can create an example.

> >But what should it do it if there are not enough characters (less than

'n')

> >because of

> >- not text item in text (image, table)

> >- line break

> >?

> >

> >>

> >> How to select 'n' number of characters from the caret position, left or

> >right.

> >>

> >> jimmy

> >

> >

>





Powered by ABC Amber Outlook Express Converter