TMSFMXRichEditor (RTF/RTE Ex/-Import)

Hello TMS community,


we are trying to save RTF-Input (From the TMSFMXRichEditor component) in our database and display it on Mac OS and Windows clients (DataSnap Server-Client Application).

For our windows clients we just saved the input of .ContentAsRTE in our database. That, however, appears not the be interchangeable with the component on clients in Mac OS.
With the newest components, I can't even get the text as RTE on a Mac client. If we try to load from it, it also fails (Unknown Component).

Another option seems to just save the info in .rtf-format (as that is more platform independent). With .rtf-format the displayed picture height and width though is not saved correctly.
If we enter a  picture with fixed resolution, the setting is not applied in the rtf string and thus not correctly saved and viewed.

What is the best way of action to get and save the same viewing result on both platforms?


Using RTE should be 100% compatible between Windows & macOS. Are you saving this RTE in a binary blob field?

Yes, we're saving to a binary field (bytea in postgres db). ContentAsRTE returns the datastring of a stringstream which leads to this:


mtRTE.FieldByName('rtefield').AsString := edtRTE.ContentAsRTE;
saving/loading is done with TFDMemTables (mtRTE).

Are we doing this wrong? Could encoding/locale be an issue?
On Mac OS the following error occurs, windows it's working fine:
(translates to: Error while reading [...] doesn't exist)


I cannot really see a reason for this. Do you reload what was actually saved from the macOS app?
Do you reload data that was saved by the exact same version of TMSFMXRichEditor?

We don't set the data from macOS - It's "only" read on that platform as of now. So the application starts and we fill the .ContentAsRTE from the global database in the blank RichEditor of the client software.
There is another administrative client on windows in which we set the actual database entry.


The version is exactly the same as I compiled our client for macOS and Windows at the same time to test the functionality is working cross-platform (also true for the administrative part).

Would a demo help you identify a possible cause? It's not much that is happening code-wise from our side.
Maybe we could just use a sqlite database, fill it and copy that over.

We sent in a demo application a few days ago. Since then I haven't really had the time to figure much out on my own (haven't heard back from you yet).


Today I looked into the topic again and found out, that specifying a certain encoding in creating the TStringStream in the SetRTEContent and GetContentAsRTE methods (TMSFMXEditorBase) makes the RTE string readable on MacOS AND Windows. I assume it must be because of the default encoding options for the platforms?
However, now pictures I save on one platform aren't displayed on the other (only displays a blank line on loading). As I understand these are base64 serialized inside the rte. 
Can someone take another look at it/ tell me what needs to be done?
I'll probably do some digging tomorrow anyway as we need a solution to the problem. Input is appreciated.

Please note that RTE format is a binary format. You cannot use a TStringStream for this. You need a binary stream connected to a binary blob field.

I don't understand your answer - you're using TStringStream in FMX.TMSRichEditorBase (I was not speaking about my own code).
So you're basically telling me to write my own getter/setter with binary streams used (and call the provided SaveStream method (in TTMSFMXRichEditorBase))?
The GetContentAsRTE is actually the only apparently way to get the rte directly from your component (without modification of the sources).
I can do that yes, but for what reason is rte provided as string then? I want to modify as few things as possibly in the component code because that means we have to watch out when updating to newer tms versions.
Thanks for your assistance

TMSFMXRichEditor.SaveToStream(), TMSFMXRichEditor.LoadFromStream() directly work with the binary RTE stream. 

To save the RTE binary stream in a binary blob field, use code like:


var
  Stream: TStream;
begin
    Stream := DataSet.CreateBlobStream(DBField, bmWrite);
    try
      RichEditor.SaveToStream(Stream);
    finally
      Stream.Free;
    end;
end;

or  to get data:

var
  Stream: TStream;
begin
    Stream := DataSet.CreateBlobStream(DBField, bmRead);
    try
      RichEditor.Clear;
      RichEditor.LoadFromStream(Stream);
    finally
      Stream.Free;
    end;
end;



Bruno Fierens2018-05-23 09:44:59