1. Computing

TMemo, TRichEdit - Delphi Usage Examples, Tips and Tricks

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.

Append or Insert RTF from One RichEdit to Another
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.

Add a Standard Context (popup) Menu to Delphi's TRichEdit
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

Set TRichEdit Print Margins Programatically
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.

TRichEditURL - hyperlink aware RichEdit
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.

How to get the Selected Text from a Memo control
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...

Positioning the Caret in a Line in a Memo or RichEdit
Set where the cursor is in a Memo control...

How to get the Current Line and Column from a Memo
Need to locate the line and column of the caret position in a Memo?

Adding URL hyperlink functionality to RichEdit
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.

Formatting Lines in Rich Edit using Delphi's SelText and SelStart
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.

How to click-and-select a line in TMemo
Here's how to select a row (line) of text in a TMemo control by clicking on it...

Search and Replace in a RichEdit
The following code snippet will search for a string and replace it with Replacement String in RichEdit...

Get the RTF formatting from a RichEdit
Here's how to get the pure RTF formatted text from a TRichEdit control...

Copy RTF Text/Formatting From one TRichEdit to Another
Here's how to copy the text from one RichEdit to another, without loosing the RTF formatting...

What's the Word Under the Mouse Cursor in a TRichEdit?
How to get the word under the mouse, while the mouse is moving over the RichEdit.

How to set the Margins in a TMemo Delphi Control
To set margins in a memo control, EM_SETRECT message is sent to Memo to fix the size of the canvas of the component...

Implement Overwrite for a TMemo
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.

Place a TCheckBox inside a TRichEdit
For the following example, create a new form, drop a TRichEdit (RichEdit1) on it and create the checkbox (acb) in the FormCreate() event...

Hide the Caret (text cursor) for a TMemo component
Here's a sample code showing how to hide the caret in Memo1 (TMemo) component on Form1 (TForm)...

Disable CTRL+V Shortcut Key for a TMemo and TRichEdit
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.

Set Tab Stops for TMemo
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.

How to add the "Select All (CTRL+A)" functionality to TMemo/TDBMemo
Here's how to implement the code for the CTRL+A key combination ("Select All") for TMemo or TDBMemo...

How to Print the Content of a TMemo component
Simple procedure that prints the content (string lines) of a Memo component..

TMemoBar - TMemo extender
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.

Scrolling Memo Text Programmatically
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.

©2014 About.com. All rights reserved.