trichview.com

trichview.support




Re: how to get text statistics count?


Return to index


Author

Message

Sergey Tkachenko

Posted: 11/08/2004 22:29:48


> I posted an example a while back, and Sergey has posted at least one

> example, I think.


This one is the fourth copy of word count example :)


Word count:


You can use a class from

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

You need a unit RVWordEnum.pas from there (other files are specific for some

spell

checkers).


Create a class


TWordCounter = class(TRVWordEnumerator)

private

    FCounter: Integer;

protected

    function ProcessWord: Boolean; override;

public

   function GetWordCount(rve: TCustomRichViewEdit): Integer;

end;


function TWordCounter.ProcessWord: Boolean;

begin

  inc(FCounter);

  Result := True;

end;


function TWordCounter.GetWordCount(rve: TCustomRichViewEdit): Integer;

begin

  FCounter := 0;

  Run(rve, rvesFromStart);

  Result := FCounter;

end;


(this function treats word written with two different fonts as two words)


==========================


Line count


Line count is not a document characteristic (unless "no-wrap" option is

included in all paragraphs).


MyRichView.GetLineNo(MyRichView.ItemCount-1,

  MyRichView.GetOffsAfterItem(MyRichView.ItemCount-1))

- returns a number of lines in MyRichView.

But it counts table as one line, and depends on window width (after

resizing, a number of lines can change)


==========================


Character count


function GetCharCount(RVData: TCustomRVData): Integer;

var i,r,c,StyleNo: Integer;

    table: TRVTableItemInfo;

begin

  Result := 0;

  for i := 0 to RVData.ItemCount-1 do

  begin

    StyleNo := RVData.GetItemStyle(i);

    if StyleNo>=0 then

      inc(Result, RVData.ItemLength(i))

    else if StyleNo=rvsTable then

    begin

      table := TRVTableItemInfo(RVData.GetItem(i));

      for r := 0 to table.Rows.Count-1 do

        for c := 0 to table.Rows[r].Count-1 do

          if table.Cells[r,c]<>nil then

            inc(Result, GetCharCount(table.Cells[r,c].GetRVData));

    end;

  end;

end;





Powered by ABC Amber Outlook Express Converter