I would like to search all records including a given text from database, which has a field containing RichViewEdit data.
A simple method is that using database scrolling function as follows:
aTbale.first;
while not aTbale.EOF do begin
if DBRichViewEdit.searchtext() then begin
...
end;
aTable.Next;
end;
But the database table is a master table, i.e., it has many detail database tables.
I think this method is not efficient.
So I want to use a cloned database table which is only for searching, and the table is not linked a DBRichViewEdit.
if there is a external text searching function like
function RVSearchText( RVDBData, aText, SearchOption) :boolean;
,this is more efficeint maybe.
Is there another method for searching a text directly from database field value?
Thanks in advance.
Seungho Jung
How to search text directly from database field
-
- Site Admin
- Posts: 17565
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
It's quite a complicated work to parse RVF document from database without using trichview control.
However, using TDBRichView/TDBRichViewEdit with SearchText is not the fastest way, because TDBRichView/TDBRichViewEdit formats document after loading. Formatting is the slowest operation, it takes longer than loading and searching. So if you just load document, without formatting, it would be much faster.
SearchText selects the found text, so it requires formatted trichview For unformatted trichviews, we need to use another method.
So, the procedure would be
However, using TDBRichView/TDBRichViewEdit with SearchText is not the fastest way, because TDBRichView/TDBRichViewEdit formats document after loading. Formatting is the slowest operation, it takes longer than loading and searching. So if you just load document, without formatting, it would be much faster.
SearchText selects the found text, so it requires formatted trichview For unformatted trichviews, we need to use another method.
So, the procedure would be
Code: Select all
while not aTable.EOF do begin
Stream := aTable.CreateBlobStream(aTable.FieldByName(FieldName), bmRead);
HiddenRichView.LoadFromStream(Stream, rvutNo);
Stream.Free;
if ContainsText(HiddenRichView.RVData, s) then begin
...
end;
aTable.Next;
end;
Code: Select all
function ContainsText(RVData: TCustomRVData; const s: String);
var i,r,c: Integer;
table: TRVTableItemInfo;
ItemText: String;
begin
for i := 0 to RVData.ItemCount-1 do
if RVData.GetItemStyle(i)>=0 then begin // this is a text item
ItemText := RVData.GetItemTextA(i);
// you can change the next line to support search options // ignore case, etc.
Result := AnsiPos(s, ItemText)>0;
if Result then
exit;
end
else if RVData.GetItemStyle(i)=rvsTable then begin
table := TRVTableItemInfo(RVData.GetItem(i));
for r := 0 to table.RowCount-1 do
for c := 0 to table.ColCount-1 do
if table.Cells[r,c]<>nil then begin
Result := ContainsText(table.Cells[r,c].GetRVData, s);
if Result then
exit;
end;
end;
Result := False;
end;
I am tried this code, it works fine, but when there are hyper-links in text it throws exception like:
Seems it in RVFReadTag function, but I can't trace as there are no sources in trial
Or may be there better way to fast search several documents (from database) not displaying it?
Code: Select all
Exception class EConvertError with message ''http://www.google.com' is not a valid integer value'.
Or may be there better way to fast search several documents (from database) not displaying it?
-
- Site Admin
- Posts: 17565
- Joined: Sat Aug 27, 2005 10:28 am
- Contact: