RTF not formatted in RichView Editor
Posted: Tue Nov 08, 2011 4:56 pm
Hi.
This worked using D2007 + TRichView V12.3 but I am having trouble getting it to work with Delphi XE2 and TRichView V13.5 (Unicode).
My code is as follows:
{------------------------------------------------------------------------------}
{ Transfer the Text into the Memory Stream object within the Rich }
{ View Editor so that it may display it in the OnShow event. Then call the }
{ editor. }
{ On return from the editor, transfer the modified RTF text to the database. }
{------------------------------------------------------------------------------}
procedure TRichViewEditorTest.StandaloneDBRichEditDblClick (Sender: TObject);
begin
RichViewEditor := TRichViewEditor.Create (RichViewEditorTest);
try
RichViewEditor.Text_Memory_Stream := TMemoryStream.Create;
try
StandAloneDBRichEdit.Lines.SaveToStream(RichViewEditor.Text_Memory_Stream, TEncoding.Unicode);
RichViewEditor.PopupParent := RichViewEditorTest;
RichViewEditor.ShowModal;
if (RichViewEditor.Text_Changed) then
begin
if ((QryRawData.State <> dsEdit) and
(QryRawData.State <> dsInsert)) then
QryRawData.Edit;
RichViewEditor.Text_Memory_Stream.Position := 0;
StandAloneDBRichEdit.Lines.LoadFromStream(RichViewEditor.Text_Memory_Stream);
StandAloneDBRichEdit.CopyRichEdittoBlob(QryRawDataCLOB_FIELD);
QryRawData.Post;
end;
finally
RichViewEditor.Text_Memory_Stream.Free;
end;
finally
RichViewEditor.Free;
end;
end;
----------------------------------------------------------------
Inside the editor:
{------------------------------------------------------------------------------}
{ Load the Definition Text into the RichViewEdit object. }
{------------------------------------------------------------------------------}
procedure TRichViewEditor.FormShow (Sender: TObject);
begin
Text_Memory_Stream.Position := 0;
RichTextRichViewEdit.Clear;
RichTextRichViewEdit.LoadRTFFromStream(Text_Memory_Stream);
RichTextRichViewEdit.Format;
RTF_Modified := False;
Text_Changed := False;
end;
{------------------------------------------------------------------------------}
{ Implement Save differently to the standard action -- save to the database, }
{ as follows: }
{ - Get text into a local string variable. }
{ - Change all instances of "\chcbpat<N>" to "\highlight<N>". }
{ - Transfer the string into the (output) TMemoryStream. }
{------------------------------------------------------------------------------}
procedure TRichViewEditor.rvActionSave1Execute (Sender: TObject);
var
Local_String: string;
begin
{------------------------------------------------------}
{ Get the RTF text into a local string variable. }
{------------------------------------------------------}
Text_Memory_Stream.Clear;
RichTextRichViewEdit.SaveRTFToStream (Text_Memory_Stream, False);
SetLength (Local_String, TRUNC(Text_Memory_Stream.Size / StringElementSize(Local_String)));
Text_Memory_Stream.Position := 0;
Defn_Text_Memory_Stream.ReadBuffer(PRVAnsiChar(Local_String)^, ByteLength(Local_String));
{------------------------------------------------------}
{ Change all instances of the "\chcbpat<N>" keyword }
{ to "\highlight<N>". }
{------------------------------------------------------}
Local_String := StrUtils.ReplaceStr (Local_String, '\chcbpat', '\highlight');
{------------------------------------------------------}
{ Transfer the modified string into the (output) }
{ TMemoryStream. }
{ This code does not, strictly speaking, put the RTF }
{ into the database, only into the output buffer!!! }
{------------------------------------------------------}
Defn_Text_Memory_Stream.Clear;
Defn_Text_Memory_Stream.WriteBuffer (Pointer(Local_String)^, ByteLength(Local_String));
RTF_Modified := False;
Text_Changed := True;
end;
+++++++++++++++++++++++++++++++++++++++++++++++
What I see in the Delphi 2007 version editor is:
And what I see in the Delphi XE2 version editor is:
What am I doing wrong ???
All assistance gratefully received.
Jim
This worked using D2007 + TRichView V12.3 but I am having trouble getting it to work with Delphi XE2 and TRichView V13.5 (Unicode).
My code is as follows:
{------------------------------------------------------------------------------}
{ Transfer the Text into the Memory Stream object within the Rich }
{ View Editor so that it may display it in the OnShow event. Then call the }
{ editor. }
{ On return from the editor, transfer the modified RTF text to the database. }
{------------------------------------------------------------------------------}
procedure TRichViewEditorTest.StandaloneDBRichEditDblClick (Sender: TObject);
begin
RichViewEditor := TRichViewEditor.Create (RichViewEditorTest);
try
RichViewEditor.Text_Memory_Stream := TMemoryStream.Create;
try
StandAloneDBRichEdit.Lines.SaveToStream(RichViewEditor.Text_Memory_Stream, TEncoding.Unicode);
RichViewEditor.PopupParent := RichViewEditorTest;
RichViewEditor.ShowModal;
if (RichViewEditor.Text_Changed) then
begin
if ((QryRawData.State <> dsEdit) and
(QryRawData.State <> dsInsert)) then
QryRawData.Edit;
RichViewEditor.Text_Memory_Stream.Position := 0;
StandAloneDBRichEdit.Lines.LoadFromStream(RichViewEditor.Text_Memory_Stream);
StandAloneDBRichEdit.CopyRichEdittoBlob(QryRawDataCLOB_FIELD);
QryRawData.Post;
end;
finally
RichViewEditor.Text_Memory_Stream.Free;
end;
finally
RichViewEditor.Free;
end;
end;
----------------------------------------------------------------
Inside the editor:
{------------------------------------------------------------------------------}
{ Load the Definition Text into the RichViewEdit object. }
{------------------------------------------------------------------------------}
procedure TRichViewEditor.FormShow (Sender: TObject);
begin
Text_Memory_Stream.Position := 0;
RichTextRichViewEdit.Clear;
RichTextRichViewEdit.LoadRTFFromStream(Text_Memory_Stream);
RichTextRichViewEdit.Format;
RTF_Modified := False;
Text_Changed := False;
end;
{------------------------------------------------------------------------------}
{ Implement Save differently to the standard action -- save to the database, }
{ as follows: }
{ - Get text into a local string variable. }
{ - Change all instances of "\chcbpat<N>" to "\highlight<N>". }
{ - Transfer the string into the (output) TMemoryStream. }
{------------------------------------------------------------------------------}
procedure TRichViewEditor.rvActionSave1Execute (Sender: TObject);
var
Local_String: string;
begin
{------------------------------------------------------}
{ Get the RTF text into a local string variable. }
{------------------------------------------------------}
Text_Memory_Stream.Clear;
RichTextRichViewEdit.SaveRTFToStream (Text_Memory_Stream, False);
SetLength (Local_String, TRUNC(Text_Memory_Stream.Size / StringElementSize(Local_String)));
Text_Memory_Stream.Position := 0;
Defn_Text_Memory_Stream.ReadBuffer(PRVAnsiChar(Local_String)^, ByteLength(Local_String));
{------------------------------------------------------}
{ Change all instances of the "\chcbpat<N>" keyword }
{ to "\highlight<N>". }
{------------------------------------------------------}
Local_String := StrUtils.ReplaceStr (Local_String, '\chcbpat', '\highlight');
{------------------------------------------------------}
{ Transfer the modified string into the (output) }
{ TMemoryStream. }
{ This code does not, strictly speaking, put the RTF }
{ into the database, only into the output buffer!!! }
{------------------------------------------------------}
Defn_Text_Memory_Stream.Clear;
Defn_Text_Memory_Stream.WriteBuffer (Pointer(Local_String)^, ByteLength(Local_String));
RTF_Modified := False;
Text_Changed := True;
end;
+++++++++++++++++++++++++++++++++++++++++++++++
What I see in the Delphi 2007 version editor is:
And what I see in the Delphi XE2 version editor is:
What am I doing wrong ???
All assistance gratefully received.
Jim