trichview.com

trichview.support




Re: Iterate through word


Return to index


Author

Message

Sergey Tkachenko

Posted: 11/23/2003 16:37:47


The simplest solution: using TRVWordEnumerator class from

http://www.trichview.com/resources/spell/rvspell.zip (RVWordEnum.pas)

You need to create a class inherited from it.

Below is an example applying the 1st text style to all "words" consisting

only of digits.


type

  TNumberColorer = class (TRVWordEnumerator)

  private

    FEdit: TCustomRichViewEdit;

  public

    procedure Run(Edit: TCustomRichViewEdit);

    function ProcessWord: Boolean; override;

  end;


function TNumberColorer.ProcessWord: Boolean;

var i: Integer;

    AllDigits: Boolean;

begin

  Result := True;

  AllDigits := True;

  for i := 1 to Length(FWord) do

    if not (FWord[i] in ['0'..'9']) then begin

      AllDigits := False;

      break;

    end;

  if not AllDigits then

    exit;

  SelectCurrentWord;

  FEdit.ApplyTextStyle(1); // or ApplyStyleConversion or whatever

  FWordChanged := True;

end;


procedure TNumberColorer.Run(Edit: TCustomRichViewEdit);

begin

  FEdit := Edit;

  inherited Run(Edit, rvesFromStart);

end;


procedure TForm1.Button5Click(Sender: TObject);

var nc: TNumberColorer;

begin

  LockWindowUpdate(rve.Handle);

  nc := TNumberColorer.Create;

  try

    nc.Run(rve);

  finally

    nc.Free;

    LockWindowUpdate(0);

  end;

end;





Powered by ABC Amber Outlook Express Converter