[Overview][Constants][Types][Classes][Procedures and functions][Index] | Reference for unit 'StdCtrls' (#lcl)

# TMemo

[Properties (by Name)] [Methods (by Name)] [Events (by Name)]

Control used to display and edit multi-line text.

## Declaration

Source position: stdctrls.pp line 1020

`type TMemo = class(TCustomMemo)`
`published`
`property Align: TAlign;` |  | Specifies the placement of the control on its Parent control.
`property Alignment: TAlignment;` |  | The horizontal alignment for the text in the control (left, right, or centered).
`property Anchors: TAnchors;` |  | The set of anchor definitions for this control.
`property BidiMode: TBiDiMode;` |  | Indicates whether text controls use in bi-directional reading.
`property BorderSpacing: TControlBorderSpacing;` |  | Determines the inner and outer border spacing for this control.
`property BorderStyle: TBorderStyle;` |  | Indicates the line style drawn as a border around the control.
`property CharCase: TEditCharCase;` |  | Controls the character case applied to values entered in the control.
`property Color: TColor;` |  | The background color for the control.
`property Constraints: TSizeConstraints;` |  | Contains the minimum and maximum Width and Height for the control.
`property DoubleBuffered: Boolean;` |  | When enabled, it reduces flicker when the control is painted.
`property DragCursor: TCursor;` |  | The cursor shape shown during a drag operation.
`property DragKind: TDragKind;` |  | Indicates the action performed for a drag operation: drag-and-drop or drag-and-dock.
`property DragMode: TDragMode;` |  | Determines how a drag operation is started for the control.
`property Enabled: Boolean;` |  | Determines whether the control responds to mouse or keyboard input.
`property Font: TFont;` |  | The font to be used for text display in this control.
`property HideSelection: Boolean;` |  | Determines if selected text to be hidden when the control does not have focus.
`property Lines: TStrings;` |  | Contains the individual lines of text in the multi-line edit control.
`property MaxLength: Integer;` |  | The maximum length of the value entered in Text, or 0 (zero) for unlimited length.
`property ParentBidiMode: Boolean;` |  | Indicates whether the BiDiMode settings in the Parent control are used.
`property ParentColor: Boolean;` |  | Use the Color from the Parent control, when enabled.
`property ParentDoubleBuffered: Boolean;` |  | Value for the DoubleBuffered property in a Parent control.
`property ParentFont: Boolean;` |  | Indicates if the Font from the Parent control is used in the control.
`property PopupMenu: TPopupMenu;` |  | A context-sensitive menu that pops up when the right mouse button is clicked over this control.
`property ParentShowHint: Boolean;` |  | If True, the value of ShowHint for the control will be the same as the one from the Parent. Default is True.
`property ReadOnly: Boolean;` |  | Indicates if the user is prevented from changing the value for the Text in the control.
`property ScrollBars: TScrollStyle;` |  | Defines the vertical and/or horizontal scrollbars used in the control.
`property ShowHint: Boolean;` |  | Enables Hint display for the control.
`property TabOrder: TTabOrder;` |  | Indicates the navigation order for the control when the user presses the Tab or Shift+Tab key.
`property TabStop: Boolean;` |  | Enables keyboard navigation using the Tab or Shift+Tab keys.
`property Visible: Boolean;` |  | Allows the control, and all of its children, to be displayed or hidden.
`property WantReturns: Boolean;` |  | Allows the user to insert Return characters (line breaks) into the text.
`property WantTabs: Boolean;` |  | Allows Tab characters to be entered into the text.
`property WordWrap: Boolean;` |  | Allows long lines (paragraphs) to wrap into multiple display lines.
`property OnChange: TNotifyEvent;` |  | Event handler signalled when the text for the control is changed.
`property OnClick: TNotifyEvent;` |  | Notification handler for mouse clicks.
`property OnContextPopup: TContextPopupEvent;` |  | Invoked when a context-sensitive pop-up menu is requested.
`property OnDblClick: TNotifyEvent;` |  | Event handler signalled when a mouse double click occurs in the control.
`property OnDragDrop: TDragDropEvent;` |  | Event handler signalled when an object is dropped onto the control.
`property OnDragOver: TDragOverEvent;` |  | Event handler signalled when a control is dragged over the control instance.
`property OnEditingDone: TNotifyEvent;` |  | Event handler signalled when editing is completed for the control.
`property OnEndDrag: TEndDragEvent;` |  | Event handler signalled for the end of a drag-drop operation.
`property OnEnter: TNotifyEvent;` |  | Event handler signalled when the control receives focus.
`property OnExit: TNotifyEvent;` |  | Event handler signalled when the control loses focus.
`property OnKeyDown: TKeyEvent;` |  | Event handler signalled for key down keyboard events.
`property OnKeyPress: TKeyPressEvent;` |  | Event handler signalled for character data entered by the user.
`property OnKeyUp: TKeyEvent;` |  | Event handler signalled when a key up event has occurred for the control.
`property OnMouseDown: TMouseEvent;` |  | Event handler signalled when a mouse down event is handled for the control.
`property OnMouseEnter: TNotifyEvent;` |  | Event handler signalled when the mouse pointer has entered the control.
`property OnMouseLeave: TNotifyEvent;` |  | Event handler signalled when the mouse pointer has left the control.
`property OnMouseMove: TMouseMoveEvent;` |  | Event handler signalled when the mouse pointer is moved in the control.
`property OnMouseUp: TMouseEvent;` |  | Event handler signalled when a mouse up event is handled for the control.
`property OnMouseWheel: TMouseWheelEvent;` |  | Event handler for mouse wheel turned.
`property OnMouseWheelDown: TMouseWheelUpDownEvent;` |  | Event handler signalled for a downward movement of the mouse wheel.
`property OnMouseWheelUp: TMouseWheelUpDownEvent;` |  | Event handler signalled for an upward movement of the mouse wheel.
`property OnMouseWheelHorz: TMouseWheelEvent;` |  | Event handler signalled for a horizontal movement of the mouse wheel.
`property OnMouseWheelLeft: TMouseWheelUpDownEvent;` |  | Event handler signalled for a leftward movement of the mouse wheel.
`property OnMouseWheelRight: TMouseWheelUpDownEvent;` |  | Event handler signalled for a rightward movement of the mouse wheel.
`property OnResize: TNotifyEvent;` |  | Notification handler for a resize of the control.
`property OnStartDrag: TStartDragEvent;` |  | Event handler signalled for the start of a dragging operation.
`property OnUTF8KeyPress: TUTF8KeyPressEvent;` |  | Handler for a character entered by the user.
`end;`

## Inheritance

`TMemo` |  | Control used to display and edit multi-line text.
`TCustomMemo` |  | The base class for multi-line text controls.
`TCustomEdit` |  | The base class for controls presenting editable text.
`TWinControl` |  | Implements a windowed control which can contain other child controls.
`TControl` |  | The base class for visible controls.
`TLCLComponent` |  | The base class for LCL components which have an associated widget.
`TComponent`
?
`TObject`

## Description

TMemo is a TCustomMemo descendant which implements a multi-line text edit control. TMemo sets the visibility for properties introduced in TCustomMemo, but does not introduce any new methods.

The textual values in the multi-line control can be accessed using the Lines property. An individual line of text can be accessed by its ordinal position in the list of values. For example:

    // var sContent: String; ...
    sContent := AMemo.Lines[2];

This provides access to the third value in List (index positions are zero-based).

The values for all of the text in Lines can be retrieved as a single String using the Text property in the TStrings class instance. Each line of text is separated by the LineEnding character sequence for the host platform or operating system. For example:

    // var sContent: String;
    sContent := AMemo.Lines.Text;

Please note: There is a difference in TCustomMemo / TMemo between the Text and Lines properties. Text is actually the Caption for the control as inherited from TControl. Lines is the multi-line TStrings instance specific to the memo control. Setting the control value using Text does NOT cause the Modified property to be updated. Setting the value using the Lines property does cause the Modified property to be updated.

This is important if an OnChange event handler is used to detect changes to the value in the control, and you need to identify whether the change was performed in program code. You can identify a programmatic change by manipulating the value in Modified.

For changes in program code, set Modified to False before setting the value using the Text property. If Modified is False when OnChange is signalled, the change occurred in program code. Modified can be set as desired in your program code after the value is assigned to Text. For example:

    // use Modified and Text to track program changes
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      Memo1.Modified := False;
      Memo1.Text := 'Whiskey' + LineEnding + 'Tango' + LineEnding + 'Foxtrot';
      Memo1.Modified := True;
    end;

    procedure TForm1.Memo1Change(Sender: TObject);
    begin
      if not TCustomMemo(Sender).Modified then
         StaticText1.Caption := 'Memo changed in code'
      else
         StaticText1.Caption := 'Memo changed by user';
    end;

Changes entered by the user are applied when methods update the Lines property in the control. As a result, Modified is set to True. If Modified is True in OnChange, the change was triggered by user interaction with the control.

The value in Modified is retained when the control gains or loses focus whether by keyboard navigation or by using the mouse.

The text displayed in the control uses the attributes defined in the Font property. No capabilities are provided for formatting individual characters, words, or lines in the content for the control.

Both horizontal and vertical scrollbars can be used in the control. Use the ScrollBar property to define the scrollbars displayed for the control. It can be used to enable automatic scrollbars which are only displayed when the content for the control does not fit within its bounds.

Use the Append method to add a line to text to the values in Lines.

Use the WantTabs and WantReturns properties to determine whether the corresponding keys are captured and stored in Lines. This affects the way control messages are applied to the control.

Use WordWrap to indicate if the control should automatically wrap a line of text longer than the visible area for the control.

Applications should use TEdit for a single line edit control.

## See also

HowToUseStdCtrls |  | How to use StdCtrls, ComCtrls or ExtCtrls.
TCustomMemo |  | The base class for multi-line text controls.
TEdit |  | Implements an edit control with a single line of text.