alvaroc
alvaroc

Reputation: 469

TJvRichEdit not setting Text properly under Delphi 10

I´m migrating a Delphi 2007 application to Delphi 10.3. One of my forms has a TJvDBRichEdit that is associated with a BLOB sub_type text Firebird 3.0/64 database. Both Delphi versions use the same JVCL version.

I later (in another module) use the contents of the field, to convert it to HMTL using a TJvRichEdit (not DB).

Var
 HTML : TStringList;     

JvRichEditcontrol.Text := table.BLOBField.AsString;
JvRichEditToHtml.ConvertToHtmlStrings(JvRichEditcontrol,HTML);

This runs smoothly on Delphi on 2007. Let´s say the field contains
'{\rtf1\ansi\deff0{\fonttbl{\f0\fnil\fcharset0 Tahoma;}} \viewkind4\uc1\pard\lang2058\b\i\f0\fs16 Italic and bold\b0\i0\par } '

After reading back JvRichEditcontrol.Text it returns
'Italic and bold'
However, for Delphi 10.3 returns the very same text
'{\rtf1\ansi\deff0{\fonttbl{\f0\fnil\fcharset0 Tahoma;}} \viewkind4\uc1\pard\lang2058\b\i\f0\fs16 Italic and bold\b0\i0\par } '
and then, ConvertToHtmlStrings returns HTML with RTF tags embedded

<P STYLE=3D"text-align: left;">
<SPAN style=3D"color: #000000; font-size: 8pt; font-family: Tahoma;">
{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil\fcharset0 Tahoma;}}
<BR>\viewkind4\uc1\pard\lang2058\b\i\f0\fs16 Italic and bold\ul\par
<BR>}
</SPAN>
</P>

It should return

<P STYLE=3D"text-align: left;">
<SPAN style=3D"color: #000000; font-size: 8pt; font-family: Tahoma;">
<BR><b><i>Italic and bold</i></b>  
<BR>  
</SPAN>  
</P>

This is what I have tried, with same result

  1. Playing with the PlainText and StreamFormat properties
  2. Using a TRichEdit instead of a TJvRichEdit
  3. Pasting from the clipboard
  4. Loading from a file

Curiously, TJvDBRichEdit works fine. Gets the text from the field and displays properly. Being a descendant of TJvRichEdit it should set the text somewhere (I have debugged a lot but so far, I´ve been unable to find how does it set it)

Am I missing something here? Does it have something to do with the Delphi 10 UnicodeString?
How do I correctly set the TJvRichEdit text property? Maybe I could use the TJvDBRichEdit but that implies passing it as a parameter or the like since the code that uses its contents (and many others from other forms) is a TDatamodule that handles the logic, and so, it currently receives the text from the field (in both Delphi 2007 and 10.3)

Upvotes: 0

Views: 109

Answers (1)

alvaroc
alvaroc

Reputation: 469

Oversimplified, assign using a string stream:

Var
SS : TStringStream;

SS := TStringStream.Create(someString);
JvRichEdit.Lines.LoadFromStream(SS);

PlainText is false and StreamFormat is sfDefault

I still don´t know what is the problem. Setting the text property has the same code on both 2007 and 10.3 despite the directives, so the problem should be deep buried in the runtime.

// Delphi 2007
procedure TControl.SetText(const Value: TCaption);
begin
if GetText <> Value then SetTextBuf(PChar(Value));
end;

procedure TControl.SetTextBuf(Buffer: PChar); begin
Perform(WM_SETTEXT, 0, Longint(Buffer));
Perform(CM_TEXTCHANGED, 0,0);
end;

// Delphi 10.3
procedure TControl.SetText(const Value: TCaption);
begin
if GetText <> Value then
{$IF DEFINED(CLR)}
begin
FText := Value;
Perform(CM_TEXTCHANGED, 0, 0);
end;
{$ELSE}
SetTextBuf(PChar(Value));
{$ENDIF}
end;

{$IF DEFINED(CLR)}
procedure TControl.SetTextBuf(Buffer: string);
{$ELSE}
procedure TControl.SetTextBuf(Buffer: PChar);
{$ENDIF} begin
Perform(WM_SETTEXT, 0, Buffer);
Perform(CM_TEXTCHANGED, 0, 0);
end;

Upvotes: 0

Related Questions