Issue with RTF and TBlob

We are using DevEx vcl-Components as visual components.

I have a small sample project, that shows what is happening right now.
I'll provide this in a several message.

Just to describe it here:
DevEx is reading and writing rtf to TBlobField by using TStringstream with default encoding, what should be fine because rtf is 7-Bit ASCII.

We are using TBlob in Aurelius to save datas.
But as you describe in docs we should access TBlob using AsUnicodeString.

Here is a screenshot, to show what is happening
image

Thanks for the example. Since you are using raw blob content, you should not mix it with string. This is the correct way to load the data from the blob:

      // DevEx recieves the Dataset to show Datas within Grid:
      // reading the data is also correct, because rtf is 7Bit ASCII...
      hStream := TStringStream.Create('', TEncoding.Default);
      TBlobField(hDataset.FieldByName('Blob')).SaveToStream(hStream);
      hStream.Position := 0;
      reOut.Lines.LoadFromStream(hStream);

I'm not able to change this behaviour because it's done by component DevExpress.

They get a Dataset with a TBlobField.
At the end the extract the Datas by using TBlobField.Value.

And at this point we came up to you, because it seems like TBlob is giving AsUnicodeString for this, so that Unicode is mixed with AnsiString...

Using a Getter for TBlob, it works, if we are doing things like this:

function GetBlob: TBlob;
begin
  Result.AsUnicodeString = FBlob.AsString;
end;

But this is not the way I wan't to implement for all Blobs...

It's not problem using TBlobField.Value, as long you treat it as a variant array of bytes, which is what it is, not text/string.

I see your point, but as I wrote before this is not our code and DevEx will not modify it.

So could I use TBytes instead of TBlob, so that this won't occur?
Which Fieldtype (in Dataset) will be used for TBytes?

You should maybe open request in DevE support system then. I don't know what is your dataset field type. You are treating it as string but using it as bytes. You have to pick one option.

If you are going to treat it as string, then use a string property, or flag your blob property with [DBTypeWideMemo] or [DBTypeMemo], and then make sure your dataset field is a memo or wide memo field. If you want to treat it as blob, then keep it as TBlob, don't add any attribute, and make sure your dataset field type is ftBlob.

After using Attribute DBTypeWideMemo, I could circumvent this by switching between String and UnicodeString within Entity-Getter and Setter...

procedure TEntity.SetBlob(const Value: TBlob);
begin
  FBlob.AsString := Value.AsUnicodeString;
end;

function TEntity.GetBlob: TBlob;
begin
  case enum of
    short:
      Result.AsUnicodeString := OtherEntity.Stringfield;
    rtf:
      Result.AsUnicodeString := OtherEntity.Blob.AsUnicodeString;
  end;
end;
1 Like

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

Since this thread was closed, @Silber_Felix sent us an additional follow up for this topic in private. I appreciate his effort to share information that might be useful for other users. Here it is for the record:

I would like to add some new insights to this issue.

we made a mistake by using ftWideString as TBlobField.BlobType instead of ftFmtBlob on one side...
In another case we did not even set any BlobType-Attribute, so that's why this mixed Ansi and Unicode behind...