Sign in Join
FPDoc Onlineexperiment

TCustomMemo class

In unit StdCtrls

The base class for multi-line text controls.

Declaration

pascal
TCustomMemo = class(TCustomEdit)

Inheritance

  1. TCustomMemo
  2. TCustomEdit
  3. TWinControl
  4. TControl
  5. TLCLComponent
  6. TComponent
  7. TPersistent
  8. TObject

Descends from it: TDBMemo TMemo

Description

TCustomMemo is a TCustomEdit descendant which implements the base class used for a multi-line edit control. TCustomMemo extends TCustomEdit with additional properties and methods needed for the control. Overridden methods are provided to create and initialize the control using style flags needed for the widgetset class.

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 of 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 not create instances of TCustomMemo; use TMemo instead.

See also

Properties

LinespublicContains the individual lines of text in the multi-line edit control.
HorzScrollBarpublicThe horizontal scrollbar for the control.
VertScrollBarpublicThe vertical scrollbar for the control.
ScrollBarspublicDefines the vertical and/or horizontal scrollbars used in the control.
WantReturnspublicAllows the user to insert Return characters (line breaks) into the text.
WantTabspublicAllows Tab characters to be entered into the text.
WordWrappublicAllows long lines (paragraphs) to wrap into multiple display lines.

Methods

WSRegisterClassprotectedRegisters this component class with the current WidgetSet.
CreateParamsprotectedUpdates creation flags used to create the handle for the control.
InitializeWndprotectedCopies existing string values from the widgetset class.
FinalizeWndprotectedMaintains resources in the class instance when the handle for the control is destroyed or re-created.
RealGetTextprotectedReturns the textual content stored in Lines as a single String value.
RealSetTextprotectedReplaces the value in Lines.Text.
GetCachedTextprotectedReturns the cached Text property (FCaption).
GetCaretPosprotectedGet the value for the CaretPos property.
KeyUpAfterInterfaceprotectedHandles Key Up events forwarded from the LCL interface.
SetCaretPosprotectedSets the position for the editing cursor or caret to the specified location.
SetLinesprotectedSets the value for the Lines property.
SetWantReturnsprotectedSets the value for the WantReturns property.
SetWantTabsprotectedSets the value for the WantTabs property.
SetWordWrapprotectedSets the value for the WordWrap property.
SetScrollBarsprotectedSets the value for the ScrollBars property.
LoadedprotectedPerforms actions needed when the component has been loaded using the LCL streaming mechanism.
CMWantSpecialKeyprotectedHandles control messages for Return and Tab keys when enabled in the control.
WMGetDlgCodeprotectedHandles Tab, Return, and Escape characters in control messages.
GetControlClassDefaultSizeprotectedGets the default size used for new instances of the class.
UTF8KeyPressprotectedImplements the handler for UTF8 key press events in the control.
CanShowEmulatedTextHintprotectedIndicates if an emulated TextHint can be displayed for the control.
CreatepublicConstructor for the class instance.
DestroypublicDestructor for the class instance.
AppendpublicAppends the specified text to the Lines in the control.
ScrollBypublicScrolls the visible area in the control by the specified amounts.

Inherited

From TCustomEdit (66)

AddHandlerOnChange Alignment AutoSelect AutoSelected AutoSize BorderStyle CalculatePreferredSize CanUndo CaretPos Change CharCase ChildClassAllowed Clear ClearSelection CopyToClipboard CutToClipboard DoEnter DoExit EchoMode EditingDone EmulatedTextHintStatus FontChanged GetNumbersOnly GetReadOnly GetSelLength GetSelStart GetSelText GetTextHint HideSelection Layout MaxLength Modified MouseUp NumbersOnly OnChange Options ParentColor PasswordChar PasteFromClipboard PopupMenu ReadOnly RemoveAllHandlersOfObject RemoveHandlerOnChange SelectAll SelLength SelStart SelText SetCharCase SetEchoMode SetNumbersOnly SetReadOnly SetSelLength SetSelStart SetSelText SetTextHint ShouldAutoAdjust TabOrder TabStop Text TextChanged TextHint Undo WMChar WMKillFocus WMSetFocus WndProc

From TWinControl (222)

AddControl AdjustClientRect AlignControls AllAutoSized AutoAdjustLayout AutoSizeDelayed AutoSizeDelayedHandle AutoSizeDelayedReport AutoSizePhases BeginUpdateBounds BorderWidth BoundsLockCount BroadCast Brush BrushCreated CachedClientHeight CachedClientWidth CanFocus CanSetFocus CanTab ChangeScale ChildHandlesCreated ChildKey ChildSizing ClientRectNeedsInterfaceUpdate CMBiDiModeChanged CMBorderChanged CMDoubleBufferedChanged CMEnabledChanged CMEnter CMExit CMParentDoubleBufferedChanged CMShowHintChanged CMShowingChanged CMVisibleChanged CNChar CNKeyDown CNKeyUp CNSysKeyDown CNSysKeyUp ContainsControl ControlAtPos ControlCount ControlKeyDown ControlKeyUp Controls ControlsAligned CreateBrush CreateDockManager CreateHandle CreateParented CreateParentedControl CreateSubClass CreateWnd CustomAlignInsertBefore CustomAlignPosition DefaultHandler DefWndProc DesignerDeleting DestroyHandle DestroyWnd DialogChar DisableAlign DoAddDockClient DoAdjustClientRectChange DoAlignChildControls DoAllAutoSize DoAutoSize DoChildSizingChange DockClientCount DockClients DockDrop DockManager DockOver DockSite DoConstraintsChange DoDockClientMsg DoDockOver DoDragMsg DoFlipChildren DoFloatMsg DoGetDockCaption DoKeyDownBeforeInterface DoKeyPress DoKeyUpBeforeInterface DoRemainingKeyDown DoRemainingKeyUp DoRemoveDockClient DoSendBoundsToInterface DoSendShowHideToInterface DoSetBounds DoubleBuffered DoUnDock DoUndockClientMsg DoUTF8KeyPress EnableAlign EndUpdateBounds EraseBackground FindChildControl FindNextControl FixDesignFontsPPIWithChildren FixupTabList FlipChildren Focused FormEndUpdated GetAdjustedLogicalClientRect GetBorderStyle GetChildren GetChildrenRect GetClientOrigin GetClientRect GetControlIndex GetControlOrigin GetDeviceContext GetDockCaption GetEnumeratorControls GetEnumeratorControlsReverse GetMouseCapture GetParentHandle GetPreferredSizeClientFrame GetSiteInfo GetTabOrderList GetTextLen GetTopParentHandle Handle HandleAllocated HandleNeeded InsertControl IntfGetDropFilesTarget IntfUTF8KeyPress Invalidate InvalidateBoundsRealized InvalidateClientRectCache InvalidatePreferredChildSizes IsClientHeightStored IsClientWidthStored IsControlMouseMsg IsFlipped IsResizing IsSpecialSubControl KeyDown KeyDownAfterInterface KeyDownBeforeInterface KeyPress KeyUp KeyUpBeforeInterface LockRealizeBounds MainWndProc NotifyControls OnAlignInsertBefore OnAlignPosition OnDockDrop OnDockOver OnEnter OnExit OnGetDockCaption OnGetSiteInfo OnKeyDown OnKeyPress OnKeyUp OnUnDock OnUTF8KeyPress PaintControls PaintHandler PaintTo PaintWindow ParentDoubleBuffered ParentFormHandleInitialized ParentHandlesAllocated ParentWindow PerformTab ReAlign RealizeBounds RealizeBoundsRecursive ReloadDockedControl RemoveControl RemoveFocus Repaint ScaleBy ScaleControls ScrollBy_WS SelectFirst SelectNext SendDialogChar SendMoveSizeMessages SetBorderStyle SetBounds SetChildZPosition SetColor SetControlIndex SetDockManager SetFocus SetShape SetTempCursor ShowControl Showing UnlockRealizeBounds Update UpdateControlState UpdateDockCaption UpdateShowing UseDockManager VisibleDockClientCount WindowHandle WMContextMenu WMDestroy WMEnter WMEraseBkgnd WMExit WMKeyDown WMKeyUp WMMove WMNotify WMPaint WMShowWindow WMSize WMSysChar WMSysKeyDown WMSysKeyUp WMWindowPosChanged WriteLayoutDebugReport WSSetText

From TControl (356)

AccessibleDescription AccessibleName AccessibleRole AccessibleValue Action ActionChange ActionLink ActiveDefaultControlChanged AddHandler AddHandlerOnBeforeDestruction AddHandlerOnChangeBounds AddHandlerOnEnabledChanged AddHandlerOnEnabledChanging AddHandlerOnKeyDown AddHandlerOnMouseWheel AddHandlerOnResize AddHandlerOnVisibleChanged AddHandlerOnVisibleChanging AdjustSize Align AnchorAsAlign AnchorClient AnchoredControlCount AnchoredControls AnchorHorizontalCenterTo AnchorParallel Anchors AnchorSame AnchorSide AnchorSideBottom AnchorSideChanged AnchorSideLeft AnchorSideRight AnchorSideTop AnchorToCompanion AnchorToNeighbour AnchorVerticalCenterTo AssignTo AutoSizing AutoSizingAll AutoSizingLockCount BaseBounds BaseParentClientSize BeforeDestruction BeforeDragStart BeginAutoDrag BeginAutoSizing BeginDrag BiDiMode BorderSpacing BoundsChanged BoundsRect BoundsRectForNewParent BringToFront CalculateDockSizes CanAutoSize Caption CaptureChanged CaptureMouseButtons ChangeBounds Changed CheckChildClassAllowed CheckNewParent CheckOnChangeBounds Click ClientHeight ClientOrigin ClientRect ClientToParent ClientToScreen ClientWidth CMChanged CMCursorChanged CMHintShow CMHitTest CMMouseEnter CMMouseLeave CMParentBiDiModeChanged CMParentColorChanged CMParentFontChanged CMParentShowHintChanged CMSysFontChanged CMTextChanged CNPreferredSizeChanged Color ColorIsStored ConstrainedResize Constraints ControlFontClass ControlOrigin ControlState ControlStyle ControlToScreen CreateAccessibleObject CreateControlBorderSpacing CreateFloatingDockSite Cursor DblClick DefineProperties DesktopFont DisableAutoSizing DoAutoAdjustLayout DoBorderSpacingChange DoCallKeyEventHandler DoCallMouseWheelEventHandler DoCallNotifyHandler Dock Docked DockOrientation DockTrackNoTarget DoContextPopup DoDock DoEndDock DoEndDrag DoFixDesignFontPPI DoMouseDown DoMouseUp DoMouseWheel DoMouseWheelDown DoMouseWheelHorz DoMouseWheelLeft DoMouseWheelRight DoMouseWheelUp DoOnChangeBounds DoOnParentHandleDestruction DoOnResize DoOnShowHint DoScaleFontPPI DoStartDock DoStartDrag DragCanceled DragCursor DragDrop Dragging DragKind DragMode DragOver EnableAutoSizing Enabled EnabledChanged EnabledChanging EndAutoSizing EndDrag ExecuteCancelAction ExecuteDefaultAction FindSubComponent FixDesignFontsPPI Floating FloatingDockSiteClass Font ForeignAnchorSideChanged FormIsUpdating GetAccessibleObject GetAction GetActionLinkClass GetAnchorsDependingOnParent GetCanvasScaleFactor GetChildAccessibleObjectAtPos GetClientScrollOffset GetColorResolvingParent GetCursor GetDefaultColor GetDefaultDockCaption GetDefaultHeight GetDefaultWidth GetDockEdge GetDragImages GetEnabled GetFloating GetFloatingDockSiteClass GetLogicalClientRect GetMousePosFromMessage GetPalette GetParentBackground GetParentComponent GetPopupMenu GetPreferredSize GetRGBColorResolvingParent GetScrolledClientRect GetSelectedChildAccessibleObject GetSidePosition GetTextBuf GetTopParent HandleObjectShouldBeVisible HasHelp HasParent Height HeightIsAnchored HelpContext HelpKeyword HelpType Hide Hint HostDockSite InitiateAction InvalidateControl InvalidatePreferredSize IsAParentAligning IsBorderSpacingInnerBorderStored IsCaptionStored IsControl IsControlVisible IsEnabled IsParentColor IsParentFont IsParentOf IsProcessingPaintMsg IsRightToLeft IsVisible Left LMCaptureChanged LoadedAll LRDockWidth ManualDock ManualFloat MouseCapture MouseDown MouseEnter MouseInClient MouseLeave MouseMove Notification OnChangeBounds OnClick OnConstrainedResize OnContextPopup OnDblClick OnDragDrop OnDragOver OnEditingDone OnEndDock OnEndDrag OnMouseDown OnMouseEnter OnMouseLeave OnMouseMove OnMouseUp OnMouseWheel OnMouseWheelDown OnMouseWheelHorz OnMouseWheelLeft OnMouseWheelRight OnMouseWheelUp OnQuadClick OnResize OnShowHint OnStartDock OnStartDrag OnTripleClick Parent ParentBackground ParentBiDiMode ParentDestroyingHandle ParentFont ParentFontChanged ParentShowHint ParentToClient Perform PositionDockRect QuadClick ReadBounds ReadState Refresh RemoveHandler RemoveHandlerOnBeforeDestruction RemoveHandlerOnChangeBounds RemoveHandlerOnEnabledChanged RemoveHandlerOnEnabledChanging RemoveHandlerOnKeyDown RemoveHandlerOnMouseWheel RemoveHandlerOnResize RemoveHandlerOnVisibleChanged RemoveHandlerOnVisibleChanging ReplaceDockedControl RequestAlign Resize Scale96ToFont Scale96ToForm Scale96ToScreen ScaleConstraints ScaleDesignToForm ScaleFontsPPI ScaleFontTo96 ScaleFontToScreen ScaleFormTo96 ScaleFormToDesign ScaleScreenTo96 ScaleScreenToFont ScreenToClient ScreenToControl SendToBack SessionProperties SetAction SetAlign SetAnchors SetAutoSize SetBiDiMode SetBoundsKeepBase SetCursor SetDragMode SetEnabled SetHint SetInitialBounds SetName SetParent SetParentBackground SetParentBiDiMode SetParentComponent SetTextBuf SetVisible SetZOrder Show ShowHelp ShowHint TBDockHeight Top TripleClick UndockHeight UndockWidth UpdateAnchorRules UpdateBaseBounds UpdateMouseCursor UpdateRolesForForm UseRightToLeftAlignment UseRightToLeftReading UseRightToLeftScrollBar Visible VisibleChanged VisibleChanging Width WidthIsAnchored WindowProc WMCancelMode WMLButtonDBLCLK WMLButtonDown WMLButtonQuadCLK WMLButtonTripleCLK WMLButtonUp WMMButtonDBLCLK WMMButtonDown WMMButtonQuadCLK WMMButtonTripleCLK WMMButtonUp WMMouseHWheel WMMouseMove WMMouseWheel WMRButtonDBLCLK WMRButtonDown WMRButtonQuadCLK WMRButtonTripleCLK WMRButtonUp WMXButtonDBLCLK WMXButtonDown WMXButtonQuadCLK WMXButtonTripleCLK WMXButtonUp

From TLCLComponent (6)

DecLCLRefCount GetWSComponentClass IncLCLRefCount LCLRefCount NewInstance WidgetSetClass

From TComponent (64)

_AddRef _Release CanObserve ChangeName ComObject ComponentCount ComponentIndex Components ComponentState ComponentStyle DesignInfo DestroyComponents Destroying ExecuteAction FindComponent FreeNotification FreeOnRelease GetChildOwner GetChildParent GetDeltaStreams GetEnumerator GetIDsOfNames GetNamePath GetObservers GetOwner GetTypeInfo GetTypeInfoCount iicrGetComponent InsertComponent Invoke IsImplementorOf Loading Name ObserverAdded Observers OnGetDeltaStreams Owner PaletteCreated QueryInterface ReadDeltaState ReadDeltaStream ReferenceInterface RemoveComponent RemoveFreeNotification RemoveFreeNotifications SafeCallException SetAncestor SetChildOrder SetDesigning SetDesignInstance SetInline SetSubComponent Tag ToString TToStringNameMode UpdateAction Updated UpdateRegistry Updating ValidateContainer ValidateInsert ValidateRename VCLComObject WriteState

From TPersistent (4)

Assign FPOAttachObserver FPODetachObserver FPONotifyObservers

From TObject (35)

AfterConstruction CheckDisposed ClassInfo ClassName ClassNameIs ClassParent ClassType CleanupInstance DefaultHandlerStr Dispatch DispatchStr Disposed DisposeOf Equals FieldAddress Free FreeInstance GetDisposed GetHashCode GetInterface GetInterfaceByStr GetInterfaceEntry GetInterfaceEntryByStr GetInterfaceTable GetInterfaceWeak GetLastCastErrorInfo InheritsFrom InitInstance InstanceSize MethodAddress MethodName QualifiedClassName StringMessageTable SystemHasExtendedRTTI UnitName

An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.