arrayslazarusfpc

Truncating a TMemo in Lazarus by removing first X lines


I'm using a TMemo in Lazarus to display a rolling log, but I want to limit it to the last 500 entries.

What I'd like to do is (in pseudo-code):

if (log_TMemo.Lines.Count > 500) then
   log_TMemo.Lines := log_TMemo[LinesCount - 500 to LinesCount];

TMemo contains TStrings TMemo.Lines, so I guess a want a way to copy a subset of the TStrings array.

Is there a way to do this, or is there another way?


Solution

  • Although it uses iteration, this response in the Lazarus forums works perfectly.

    while log_TMemo.Lines.Count > 500 do
        log_TMemo.Lines.Delete(0);