Hi All
I have a calculated Boolean field that it indicates to me if there is (or not) text in a field. The objective of this field is to show (in a TDBGrid) if there is text or no.
Then, if I calculate the result based on the IsNull property I do not obtain the correct result, since the field is edited by a form that contains a TDBRichViewEdit.
I need to show whether are a text in the record. Since the records are edited by a Form with a TDBRichViewEdit and other controls, although I do not even put information in the TDBRichViewEdit control, it's stores some information in the BlobField ¿right?
The property BlobSize is 0 (when IsnUll is True), but after the first "edition" no longer it returns to be 0, but an arbitrary value... depending -among other things- of the value of the RVFOptions property.
I would need something like...
CalculatedThereIsText.AsBoolean := (GetAllText(BlobField)<>'')
but, the GetAllText() function is:
function GetAllText(rv: TCustomRichView): String;
var i: Integer;
begin
if rv.ItemCount=0 then begin
Result := '';
exit;
end;
i := 0;
Result := GetItemText(rv, i);
for i := i+1 to rv.ItemCount-1 do begin
if rv.IsFromNewLine(i) then
Result := Result + #13#10;
Result := Result+GetItemText(rv, i);
end;
end;
There is some way to do this without constructing the TDBRichViewEdit control?
Thanks for readme and sorry for my english.
Tavo.
How to determine if there is text in a TBlobField
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Yes, even if the document is empty, RVF may contain information about background, margins, styles (depending on RVF option), or at least RVF header line.
It's possible to parse RVF file without TRichView, but I still recommend to use TRichView to load the document and then analyze its content.
GetAllText is not a good choice because of two reasons:
1) If the document contain one picture or table or other non-text item, this function may return ''
2) It is slow: it enumerates all items, and SomeString := SomeString + AnotherString is a very slow operation if performed many times in cycle with lage string.
Use this code:
IsEmpty := (rv.ItemCount=0) or ((rv.ItemCount=1) and (rv.GetItemStyle(0)>=0) and (rv.GetItemText(0)=''))
And it's better not to use TDBRichView or TDBRichViewEdit linked to this field for this operation. It's because they format the loaded document, and formatting is the slowest operation.
Use TRichView and this procedure:
It's possible to parse RVF file without TRichView, but I still recommend to use TRichView to load the document and then analyze its content.
GetAllText is not a good choice because of two reasons:
1) If the document contain one picture or table or other non-text item, this function may return ''
2) It is slow: it enumerates all items, and SomeString := SomeString + AnotherString is a very slow operation if performed many times in cycle with lage string.
Use this code:
IsEmpty := (rv.ItemCount=0) or ((rv.ItemCount=1) and (rv.GetItemStyle(0)>=0) and (rv.GetItemText(0)=''))
And it's better not to use TDBRichView or TDBRichViewEdit linked to this field for this operation. It's because they format the loaded document, and formatting is the slowest operation.
Use TRichView and this procedure:
Code: Select all
function LoadRVFFromField(rv: TCustomRichView; tbl: TTable;
const FieldName: String): Boolean;
var Stream: TStream;
begin
Stream := tbl.CreateBlobStream(tbl.FieldByName(FieldName), bmRead);
try
Result := rv.LoadRVFFromStream(Stream);
finally
Stream.Free;
end;
end;
Thanks.
I followed your instructions and everything works very well. I use a TRichView without parent that I construct -and destroy- parallelly to the TDBGrid.
Very many thanks.
Very many thanks.