Page 1 of 1

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

Posted: Sat Dec 03, 2005 12:48 pm
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

Posted: Sat Dec 03, 2005 2:58 pm
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;

thanks a lot

Posted: Tue Dec 06, 2005 1:51 am
by dpbug
thanks a lot