Author: Jonas Bilinkevicius
Is there a way to place a maximum number of lines in a TMemo?
Answer:
1 2 procedure TForm1.Memo1Change(Sender: TObject);
3 var4 i: Integer;
5 s: string;
6 begin7 i := Length(Memo1.Lines.Text);
8 {Limit the number of lines to 3}9 if Memo1.Lines.Count > 3 then10 begin11 s := Memo1.Lines.Text;
12 Delete(s, i, 1);
13 {Remove line wrap}14 i := Length(s);
15 while (Ord(s[i]) = 10) or (Ord(s[i]) = 13) do16 begin17 Delete(s, i, 1);
18 i := Length(s);
19 end;
20 Memo1.Lines.Text := s;
21 {posistion cursor at end of memo}22 Memo1.SelStart := Length(s);
23 Memo1.SelLength := 0;
24 ShowMessage('Over Max Lines');
25 end;
26 end;