trichview.com

trichview.support




Re: Enumerate text


Return to index


Author

Message

Sergey Tkachenko

Posted: 02/29/2004 20:58:46


Download a set of spell checkers:

http://www.trichview.com/resources/spell/rvspell.zip

From this zip file, you need only one unit: RVWordEnum.pas.

This unit contains a class that can be used to enumerate words.


Example code (applying the 1st text style to every third word):

(you can remove calls of LockWindowUpdate if they cause other components to

flicker)



// Create a new class


type

  TWordColorer = class (TRVWordEnumerator)

  private

    FEdit: TCustomRichViewEdit;

    FCounter: Integer;

  public

    procedure Run(Edit: TCustomRichViewEdit);

    function ProcessWord: Boolean; override;

  end;


function TWordColorer.ProcessWord: Boolean;

begin

  // do something with FWord variable

  inc(FCounter);

  if (FCounter mod 3)=0 then begin

    SelectCurrentWord;

    FEdit.ApplyTextStyle(1); // changing color

    // (or you can use ApplyStyleConversion)

  end;

  Result := True;

end;


procedure TWordColorer.Run(Edit: TCustomRichViewEdit);

begin

  FCounter := 0;

  FEdit := Edit;

  inherited Run(Edit, rvesFromStart);

end;


Using:


procedure TForm1.Button5Click(Sender: TObject);

var wc: TWordColorer;

begin

  LockWindowUpdate(rve.Handle);

  wc := TWordColorer.Create;

  try

    wc.Run(rve);

  finally

    wc.Free;

    LockWindowUpdate(0);

  end;

end;



>

> I want to enumerate the text in a richview word for word from beginning to

> end and then based on some criteria change the TextStyle for a word. What

> is the best way to do this enumerating ?

>





Powered by ABC Amber Outlook Express Converter