Page 1 of 1

TRichView content through DevExpress' TcxCustomGridRecord

Posted: Mon Feb 14, 2022 5:34 pm
by Alexander_Dober
Hello,

I'm looking for a way to check if content of a RichView (assigned to a column of a cxDBGrid and available via TcxCustomGridRecord.Values[<ColumnIndex>] as Variant) is "empty" i.e. the plain text. The call is from an event, where the dataset is not synced with the appropriate record, which is why I cann't the data field.

For similar tasks I'm using these 3 functions already:

function RVFToPlainText_BlobField(RVField: TField): string;
function RVFToPlainText_RichView(RichView: TCustomRichView): string;
function RVFToPlainText_Stream(Stream: TMemoryStream): string;

But none covers the current case.

I thought that using a stream is the closest option and found a suggestion for converting a variant value to a tream, similar to one from here:
http://www.trichview.com/forums/viewtop ... afc#p23310

But I get an EVariantInvalidArgError in

Code: Select all

Size := VarArrayHighBound(lVariant, 1) - VarArrayLowBound(lVariant, 1) + 1;
Is this example supposed to work in such a case at all or has it to be achieved in a different way?

Re: TRichView content through DevExpress' TcxCustomGridRecord

Posted: Tue Feb 15, 2022 8:51 am
by Sergey Tkachenko
Sorry, do you want to
- know if the content is empty
- know if the content has something except for a plain text (if yes, do you mean plain text "without images or other non text items" or "of the same font)
- get the content as a text string
?

Re: TRichView content through DevExpress' TcxCustomGridRecord

Posted: Tue Feb 15, 2022 9:32 am
by Alexander_Dober
As far as I know, the blob field as such is not empty / not null, even if the richview assigned to it is, because of the special format TRIchView is using.
I would like to know, if the richview assigned to that data field was / is empty. I believe in the past there was the advice to check for plain text.

I have a Variant value und need to know, whether it cointains some use specified content or not. It's a description field, so checking the plain text would be enough, because an image or an empty table wouldn't be a valid descriptions.

Re: TRichView content through DevExpress' TcxCustomGridRecord

Posted: Mon Feb 28, 2022 1:23 pm
by Sergey Tkachenko
Even for empty document, field content may be not empty, if the field format is RVF, RTF or DocX. It's because even empty document has fonts, settings, etc.
So the only way is loading its content to a hidden TRichView (or TRVReportHelper.RichView) and check the item count:

Code: Select all

IsEmpty := (rv.ItemCount = 0) or ((rv.ItemCount = 1) and (rv.GetItemText(0)='')

Re: TRichView content through DevExpress' TcxCustomGridRecord

Posted: Mon Mar 14, 2022 9:08 am
by Alexander_Dober
That's what I'm trying to achieve... But the content is only available as variant in this case and the mentioned example below to load the variant value into a stream doesn't work.

Re: TRichView content through DevExpress' TcxCustomGridRecord

Posted: Mon Mar 14, 2022 6:18 pm
by Sergey Tkachenko
You can open cxTRichView.pas and copy procedure LoadValue to your unit (together with VarTypeIsUnicodeStr and VarIsUnicodeStr).
This procedure loads the content of variant Value to TCustomRichView Edit. DefFont parameter can be nil.