Assignment of RV to RV

General TRichView support forum. Please post your questions here
Post Reply
jamiemi
Posts: 21
Joined: Sun Oct 30, 2005 3:33 pm

Assignment of RV to RV

Post by jamiemi »

Hello:

I am new, but I have spent the entire morning pouring over the help file and this forum. I cannot find anything that details how to assign a RichView to another RichView or descendant.

I have a message viewer; it consists of (among other controls) a TdbRichViewEdit. This is connected to an Access database; the specific field is an OLE data type.

What I have in mind is the following: When a user wants to create a new message, I want to pop up a full editor (something like the ActionTest demo, using a TRichViewEdit) and allow the user to edit it in RVF mode. Then, if the user wants to save off the message to send it, I want to put the data base into append mode, move the message from the editor to the TdbRichViewEdit and then post to the database.

Since I am new to this control set (I only bought it yesterday), there may be an easier way to do this. I tried using TMemory Stream, writing the editor to the stream, and then reading it in to the dbRichViewEdit. The save returns a failure, however, without explaining why.

Ideally, I would like to find something like:

dbMemo.Items.Assign(editor.Items);

Thanks for the help
jamie
jamiemi
Posts: 21
Joined: Sun Oct 30, 2005 3:33 pm

More information

Post by jamiemi »

The stream create actually worked - it returns TRUE and I expected it to return 0 if successful. The LoadRVTFromStream does not work if the target is the TdbRichEditView; it does work if the target is a TRichViewEdit. Is there something about connecting to the DB table that changes the behavior. Here is the code. The transfer of data from the editor is complete for RV1, but no data is saved to the database table from rtfMess.

procedure TfrmMain.btnMessNewThreadClick(Sender: TObject);
Var
Stream: TMemoryStream;
begin
Screen.Cursor := crHourglass;
Stream := TMemoryStream.Create;
Try Try
// Pop up the editor and allow the user to add info to the TRichViewEdit
If (frmEditor.ShowModal = mrOK) Then Begin

Stream.Position := 0;

// Load the document from the editor into a stream
If (NOT frmEditor.rtfMain.SaveRVFToStream(Stream, FALSE)) Then
Raise DevExcept.Create('Failed to save document to the Stream.');
Stream.Position := 0;

// Start a transaction
D.DB.StartTransaction;

D.tblMess.Append;

// This appears to work - a TRUE is returned
If (NOT rtfMess.LoadRVFFromStream(Stream)) Then
Raise DevExcept.Create('Failed to load document from stream.');

rtfMess.Format;

// reload the stream to try in a standard TRichView
Stream.Position := 0;

RV1.LoadRVFFromStream(Stream);
RV1.Format;


D.tblMess.Post;

// Finish it
D.DB.Commit;
End;
Except
On E: Exception Do Begin
If (D.DB.InTransaction) Then
D.DB.Rollback;
WriteStatus(SB, E.Message, TRUE);
End;
End;
Finally
Stream.Free;
Screen.Cursor := crDefault;
End;
end;
Sergey Tkachenko
Site Admin
Posts: 17309
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

The best way to save data from TRichViewEdit in database is writing directly into the table field, instead of copying data to TDBRichViewEdit.
See the demo: Demos\Delphi\DB Demo\2 RichViewEdit\

Why the document is not updated when you call LoadRVFFromStream of TDBRichViewEdit? Because LoadRVFFromStream is a viewer-style method*, it does not inform the component that the document was modified, so changes are not stored in the database.
The solution: call DBRichViewEdit.Change after calling LoadRVFFromStream. See the help file, topic about TDBRichViewEdit, Example 1.

* - for the difference between viewer-style and editing-style methods, see the help file, the topic "Viewer vs Editor".
Post Reply