How to limit the number of characters per line and the number of lines in a TMemo (2) (Views: 32)
Problem/Question/Abstract: Is there a way to place a maximum number of lines in a TMemo? Answer: procedure TForm1.Memo1Change(Sender: TObject); var i: Integer; s: string; begin i := Length(Memo1.Lines.Text); {Limit the number of lines to 3} if Memo1.Lines.Count > 3 then begin s := Memo1.Lines.Text; Delete(s, i, 1); {Remove line wrap} i := Length(s); while (Ord(s[i]) = 10) or (Ord(s[i]) = 13) do begin Delete(s, i, 1); i := Length(s); end; Memo1.Lines.Text := s; {posistion cursor at end of memo} Memo1.SelStart := Length(s); Memo1.SelLength := 0; ShowMessage('Over Max Lines'); end; end; |