The Memo Control

Hierarchy: TObject - TPersistent - TComponent - TControl - TWinControl - TCustomEdit - TCustomMemo - TMemo

This component provides multi-line input and output for text and other data. 

Properties

Alignment

e.g. Memo1.Alignment:=taCenter; - align text within memo; also: taLeftJustify, taRightJustify.

Lines

Lines is a TStrings object so you can use the methods of that object - Add, Append, CompareStrings, Clear, Delete, Equals, IndexOf, Insert, Move. Each line in a memo is accessible by an index, e.g. Memo1.Lines[5] - indexing starts at zero so this is line 6. 

Lines.Add

e.g. Memo1.Lines.Add - Use the Add method to add lines to a memo e.g. Memo1.Lines.Add(string). 

Lines.Clear

e.g. Memo1.Lines.Clear - clears lines of text in the memo, effectively the same as Memo1.Clear

ScrollBars

e.g. Memo1.ScrollBars:=ssBoth; - show both horizontal and vertical scroll bars; also: ssHorizontal, ssVertical, ssNone.

Methods

Clear

e.g. Memo1.Clear - clears all text from memo

ClearSelection

e.g. Memo1.ClearSelection - clears selected text

CopyToClipboard

e.g. Memo1.CopyToClipboard - copies selected text to clipboard so can be pasted into other applications

PasteFromClipboard

e.g. Memo1.PasteFromClipboard - pastes from clipboard into the memo

SelectAll

e.g. Memo1.SelectAll - select all text in memo

Undo

e.g Memo1.Undo - undo last action e.g. a delete or cut operation

Usage

To delete the default text, 'Memon' click the dieresis in the Lines property, which opens the String List Editor: 

 

Examples

In this example we send formatted data to the memo:

procedure printConsignmentline(heading, detail:string);
var
 i: integer;
 line:string;
begin
 line:=format('%-20s',[heading]) + ': '+ format('%30s',[detail]);
 ConsignmentMemo.lines.Add(line);
end;

The procedure above sets one piece of text on the left of the memo ('%-20s' sets a width of 20 characters, the '-' sets it to left-justified) and the other right-justified. 

procedure printParcelLine(p:TParcel_Record);
var line: string;
begin
 with p do
  begin
   line:=format('%4s',[ParcelID]) + format('%15s',[Length]) +  format('%12s',[Breadth])+format('%12s',[Height])+format('%12s',[Weight]) +format('%12s',[Price]);
   ConsignmentMemo.lines.add(line);
  end;
end;

The section on printing shows how the text in the memo above is printed on paper.

Back to Tutorial

Back to Palette List