TRichView content through DevExpress' TcxCustomGridRecord

General TRichView support forum. Please post your questions here
Post Reply
Alexander_Dober
Posts: 130
Joined: Fri Mar 04, 2011 3:44 am

TRichView content through DevExpress' TcxCustomGridRecord

Post 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?
Sergey Tkachenko
Site Admin
Posts: 17253
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: TRichView content through DevExpress' TcxCustomGridRecord

Post 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
?
Alexander_Dober
Posts: 130
Joined: Fri Mar 04, 2011 3:44 am

Re: TRichView content through DevExpress' TcxCustomGridRecord

Post 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.
Sergey Tkachenko
Site Admin
Posts: 17253
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: TRichView content through DevExpress' TcxCustomGridRecord

Post 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)='')
Alexander_Dober
Posts: 130
Joined: Fri Mar 04, 2011 3:44 am

Re: TRichView content through DevExpress' TcxCustomGridRecord

Post 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.
Sergey Tkachenko
Site Admin
Posts: 17253
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: TRichView content through DevExpress' TcxCustomGridRecord

Post 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.
Post Reply