stringdelphilinestmemo

Add lines to the top of a memo in Delphi


The function Memo.Lines.Add('Some text') in Delphi adds the string to the bottom of the memo. Is there any function which adds the text to the top?

For example, if the Lines property of the Memo contains:

string 1
string 2
string 3

I want to add a string string 0 before string 1. How can I do that?


Solution

  • The Lines property is a TStrings instance that supports inserting at a specified line number. The method to do so is Insert and is called like this:

    Memo.Lines.Insert(0, 'string 0');