Y si esto va a ser para todos los TMemo....
Código Delphi
[-]
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls;
type
TMemo = class(StdCtrls.TMemo)
private
FMaxLines:Integer;
FOnKeyUp: TKeyEvent;
procedure WMKeyUp(var Message: TWMKeyUp); message WM_KEYUP;
procedure SetMaxLines(Value:Integer);
protected
property OnKeyUp: TKeyEvent read FOnKeyUp write FOnKeyUp;
public
property MaxLines:Integer read FMaxLines Write SetMaxLines default 0;
end;
TForm1 = class(TForm)
ElMemo: TMemo;
procedure FormCreate(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TMemo.SetMaxLines(Value: Integer);
begin
if Value<>FMaxLines then
if Value<0 then
raise Exception.Create('A MaxLines no se le pueden asignar valores menores de cero(0).')
else
FMaxLines := Value;
end;
procedure TMemo.WMKeyUp(var Message: TWMKeyUp);
begin
if FMaxLines<>0 then
while Lines.Count > FMaxLines do
Lines.Delete(Lines.Count-1);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ElMemo.MaxLines := 3;
end;
end.
Crea una palicación desde cero... pon un memo en el formulario (llámalo ElMemo) y sustituye el código de la Unit1 por el que está aquí arriba.