Delphi's TMemo and TRichEdit controls handle multiple lines of text. TMemo is an edit box that handles multiple lines of text. TRichEdit is a memo control that supports rich text formatting. Learn how to use various multi-line text controls in Delphi's VCL.
The TRichEdit control does not expose a method to append or insert a piece of RTF text. It does have a Lines property to let you add more text - but you'll have trouble if you want to append rich text formatted content - it will be added as a (ASCII) simple text. Here's how to append or insert RTF using rich edit specific callback functions.
Delphi's implementation of the rich editor control (TRichEdit) does *not* expose the default context popup menu when the rich edit is right-clicked. Here's how to implement the default context popup for a rich edit control
Rich Edit provides a simple Print method allowing you to programmatically print the (formatted) contents of the rich edit to the active printer - with a single line of code. Unfortunately, there's no exposed functionality to set printer margins as you are accustomed to in various word processing applications.
Full source code of the TRichEditURL Delphi component, an extension to the standard RichEdit component. The TRichEditURL automatically recognizes URLs. Whenever the text in a RichEditURL matches the format of a URL, the control will display it as a hyperlink - when the link is clicked an event is raised enabling you to, for example, open a browser or send an email.
If you need to know what portion of the text a user selected in a TMemo (or TEdit) component, right after the selection was made, you can use the next code in the OnMouseUp event handler for a TMemo (named Memo1 in the code below) control...
Set where the cursor is in a Memo control...
Need to locate the line and column of the caret position in a Memo?
Here's how to add URL hyperlink functionality to a TRichEdit component - whenever the text in a RichEdit matches the format of a URL, the control will display it as a hyperlink.
While you can create nice user interface "around" the rich edit control with toolbar buttons to set and change text display attributes, adding formatted lines to rich edit programmaticaly is fairly cumbersome - as you will see.
Here's how to select a row (line) of text in a TMemo control by clicking on it...
The following code snippet will search for a string and replace it with Replacement String in RichEdit...
Here's how to get the pure RTF formatted text from a TRichEdit control...
Here's how to copy the text from one RichEdit to another, without loosing the RTF formatting...
How to get the word under the mouse, while the mouse is moving over the RichEdit.
To set margins in a memo control, EM_SETRECT message is sent to Memo to fix the size of the canvas of the component...
The example demonstrates emulation of an overwrite capability of a TMemo component. The state of the overwrite mode can be toggled by pressing the insert key.
For the following example, create a new form, drop a TRichEdit (RichEdit1) on it and create the checkbox (acb) in the FormCreate() event...
Here's a sample code showing how to hide the caret in Memo1 (TMemo) component on Form1 (TForm)...
Sometimes you need to disallow a user from using keyboard shortcuts for common clipboard operations such as copy (CTRL+C) or paste (CTRL+V) while an edit control has the input focus.
Here's how to apply Tab stops to a TMemo component. When text is entered or is copied to the control, any tab character in the text causes space to be generated up to the next tab stop.
Here's how to implement the code for the CTRL+A key combination ("Select All") for TMemo or TDBMemo...
Simple procedure that prints the content (string lines) of a Memo component..
Full source code of the MemoBar Delphi component. MemoBar can be attached to a T(Custom)Memo component to provide additional info/functionality for a Memo component.
You use the TMemo Delphi component when you need a standard Windows multiline edit control on a form. When the text does not fit the memo height scrollbars appear, a user can scroll the text using the scroll bars. Here's how to scroll the text in a Memo control from Delphi code.