how can i search a string in RVF file or RVF stream?

General TRichView support forum. Please post your questions here
Post Reply
dpbug
Posts: 6
Joined: Sun Nov 06, 2005 9:14 am

how can i search a string in RVF file or RVF stream?

Post by dpbug »

i saved the rvf stream of Trichvieweditor in a database, then i want to search some string in the rvf stream loaded from the database, how can i do it ?

thanks
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

It's not possible without loading document in TRichView.

For example:

Code: Select all

// rv is TRichView
var Stream: TStream;

  Stream := Table.CreateBlobStream(Table.FieldByName(FieldName), bmRead);
  try
    Result := rv.LoadRVFFromStream(Stream);
  finally
    Stream.Free;
  end;
  // rv.Format is not called, otherwise it would be too slow.
  Result := HasWord(rv.RVData, WordToSearch);

Code: Select all

uses CRVData, RVTable;
function HasWord(RVData: TCustomRVData; const WordToSearch: String): Boolean;
var i,r,c: Integer;
    s: String;
    table: TRVTableItemInfo;
begin
  Result := False;
  for i := 0 to RVData.ItemCount-1 do
    if RVData.GetItemStyle(i)>=0 then 
    begin // this is a text item
      s := RVData.GetItemTextA(i);
      Result := AnsiPos(WordToSearch, s)>0;
      if Result then
        exit;
    end
    else if RVData.GetItemStyle(i)=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
          begin
             Result := HasWord(table.Cells[r,c].GetRVData, WordToSearch);
             if Result then
               exit;
          end;
    end;
end;
dpbug
Posts: 6
Joined: Sun Nov 06, 2005 9:14 am

thanks a lot

Post by dpbug »

thanks a lot
Post Reply