invalid coding using TBlob with TDbWideMemo

Changing WideMemo value using Aurelius Dataset will run into
"invalid byte sequence for coding UTF8" 0x00

stepping into it:

procedure TCustomAureliusDataset.SetPropValue
...
MemberValue := Explorer.VariantToValue(Value, O);

Value is expected rtf text ending with CRLF:

'{\rtf1\ansi\deff0\nouicompat{\fonttbl{\f0\fnil Calibri;}{\f1\fnil\fcharset0 Calibri;}}'#$D#$A'{\*\generator Riched20 10.0.19041}\viewkind4\uc1 '#$D#$A'\pard\sa200\sl264\slmult1\f0\fs22\lang1031 Dimmer\par'#$D#$A'Dimm \b\fs28 dimm \b0\fs22 dum\f1  asd\f0\par'#$D#$A'\par'#$D#$A'}'#$D#$A

MemberValue is corresponding blob with byte array, including end of string #0 at the end:

(123, 0, 92, 0, 114, 0, 116, 0, 102, 0, 49, 0, 92, 0, 97, 0, 110, 0, 115, 0, 105, 0, 92, 0, 100, 0, 101, 0, 102, 0, 102, 0, 48, 0, 92, 0, 110, 0, 111, 0, 117, 0, 105, 0, 99, 0, 111, 0, 109, 0, 112, 0, 97, 0, 116, 0, 123, 0, 92, 0, 102, 0, 111, 0, 110, 0, 116, 0, 116, 0, 98, 0, 108, 0, 123, 0, 92, 0, 102, 0, 48, 0, 92, 0, 102, 0, 110, 0, 105, 0, 108, 0, 32, 0, 67, 0, 97, 0, 108, 0, 105, 0, 98, 0, 114, 0, 105, 0, 59, 0, 125, 0, 123, 0, 92, 0, 102, 0, 49, 0, 92, 0, 102, 0, 110, 0, 105, 0, 108, 0, 92, 0, 102, 0, 99, 0, 104, 0, 97, 0, 114, 0, 115, 0, 101, 0, 116, 0, 48, 0, 32, 0, 67, 0, 97, 0, 108, 0, 105, 0, 98, 0, 114, 0, 105, 0, 59, 0, 125, 0, 125, 0, 13, 0, 10, 0, 123, 0, 92, 0, 42, 0, 92, 0, 103, 0, 101, 0, 110, 0, 101, 0, 114, 0, 97, 0, 116, 0, 111, 0, 114, 0, 32, 0, 82, 0, 105, 0, 99, 0, 104, 0, 101, 0, 100, 0, 50, 0, 48, 0, 32, 0, 49, 0, 48, 0, 46, 0, 48, 0, 46, 0, 49, 0, 57, 0, 48, 0, 52, 0, 49, 0, 125, 0, 92, 0, 118, 0, 105, 0, 101, 0, 119, 0, 107, 0, 105, 0, 110, 0, 100, 0, 52, 0, 92, 0, 117, 0, 99, 0, 49, 0, 32, 0, 13, 0, 10, 0, 92, 0, 112, 0, 97, 0, 114, 0, 100, 0, 92, 0, 115, 0, 97, 0, 50, 0, 48, 0, 48, 0, 92, 0, 115, 0, 108, 0, 50, 0, 54, 0, 52, 0, 92, 0, 115, 0, 108, 0, 109, 0, 117, 0, 108, 0, 116, 0, 49, 0, 92, 0, 102, 0, 48, 0, 92, 0, 102, 0, 115, 0, 50, 0, 50, 0, 92, 0, 108, 0, 97, 0, 110, 0, 103, 0, 49, 0, 48, 0, 51, 0, 49, 0, 32, 0, 68, 0, 105, 0, 109, 0, 109, 0, 101, 0, 114, 0, 92, 0, 112, 0, 97, 0, 114, 0, 13, 0, 10, 0, 68, 0, 105, 0, 109, 0, 109, 0, 32, 0, 92, 0, 98, 0, 92, 0, 102, 0, 115, 0, 50, 0, 56, 0, 32, 0, 100, 0, 105, 0, 109, 0, 109, 0, 32, 0, 92, 0, 98, 0, 48, 0, 92, 0, 102, 0, 115, 0, 50, 0, 50, 0, 32, 0, 100, 0, 117, 0, 109, 0, 92, 0, 102, 0, 49, 0, 32, 0, 32, 0, 97, 0, 115, 0, 100, 0, 92, 0, 102, 0, 48, 0, 92, 0, 112, 0, 97, 0, 114, 0, 13, 0, 10, 0, 92, 0, 112, 0, 97, 0, 114, 0, 13, 0, 10, 0, 125, 0, 13, 0, 10, 0, 0, 0)

TBytes is set by:

class function TUtils.VariantToBytes
...
varUString: result := TEncoding.Unicode.GetBytes(string(V));

How could I solve this issue?
This Datasetfield is using TBlob property, DbTypeWideMemo is defined on Field only.

TEntity = class
private
  [DBTypeWideMemo]
  FRtfText: TBlob;
public
  // used property for Dataset
  property RtfText: TBlob read FRtfText write FRtfText;
end;

What is the field type in your dataset? It should ftWideMemo.

It is ftWideMemo.

I found out, that in System.Variants.VarToStr V ends with #13#10.
Stepping into VarToStrDef V also ends with #13#10.
But Result := V returns #13#10#0.

If #13#10#0 is set to Blob (using Postgres with UTF-8) you will recieve an exception:
#0 is not a valid char for UTF-8.

taking a look at:
https://docwiki.embarcadero.com/Libraries/Sydney/en/System.SysUtils.Trim
You will find this hint:

In the 7-bit ASCII character set defined in ANSI X3.4-1977 (C0 and G0), "control codes" are defined as all characters whose code is from 0 through 31.

The used Column-Editor is an RichEdit, and rtf is 7-bit ASCII.

I just fixed it by using

hBlob.AsUnicodeString := Trim(VarToStr(aValue));

for all ftWideMemo Fields, using TBlob behind.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.