Nat
Nat

Reputation: 9

TDBrichedit displays plain text rather than rich text

The context is that I am maintaining an application running on delphi 7 with the BDE. I programmatically assign dbricheditcontrols' datafields to allow users to edit rtf documents. When the relevant forms open, the unformatted text is displayed and then once say the person moves onto the next document, suddenly the rich text kicks in; I suspect it must be an initialisation problem of sorts, but what am I missing?

Upvotes: -1

Views: 603

Answers (1)

MartynA
MartynA

Reputation: 30735

What you say suggests that you may be going about what you are trying to do the wrong way. You say you are using a TDBRichEdit component, but if you are using it correctly, it should not require any programmatic assignment of datafields to do it: you simply need to connect the component to the TTable or TQuery you are using via a TDataSource component, and configure the DBRichEdit to access whatever field of the TTable/TQuery that stores the richedit text. That can be done a design time using the Object Inspector in the IDE to set properties and does not require any code.

So, it seems to me that either you are not using the DBRichEdit correctly, or you are trying to do something that you have not explained in your q.

You can satisfy yourself that a DBRichEdit works automatically, without needing to load or save its contents in code, as follows:

  • Open the FishFacts demo

  • Add a TDBNavigator and a TDBRichEdit to the form. Set the DataField property of DBRichEdit1 to Notes.

  • Set the ReadOnly property of Table1 to False. Then set Table1's Active property to True.

  • Compile and run the project. While it's running

  • Start WordPad.Exe and create a bit of richtext in it. Copy it to the clipboard. Click the Save speedbutton of DBNavigator1.

  • Paste the richtext into DBRichEdit1.

  • You should find that you can navigate away from and back to the edited record and the richtext will be automatically reloaded.

Also, the following code works fine for me to load the Notes field from an .Rtf file

procedure TForm1.Button1Click(Sender: TObject);
begin
  Table1.Edit;
  TMemoField(Table1.FieldByName('Notes')).LoadFromFile('D:\test.rtf');
end;

and does not initially display the unformatted text as you describe. So I'm fairly sure you problem is arising in code of yours that you haven't shown us.

Upvotes: 5

Related Questions