Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Delphi 4 - Memo component, set lines maximum?

Hello!

It's easy to set maxlength for the Memo component directly, but can the maximum of lines.count be set somehow? Directly or with code?

Can anybody help with this?

Comments

  • zibadianzibadian Member Posts: 6,349
    : Hello!
    :
    : It's easy to set maxlength for the Memo component directly, but can the maximum of lines.count be set somehow? Directly or with code?
    :
    : Can anybody help with this?
    :
    The most simple way to do this is to use the OnKeyPress() event. Each time the user presses enter (#13) then check if the count has reached a cetain value. If it has, remove the keypress by changing it to a null (#0).
  • findelphinfindelphin Member Posts: 3
    : : Hello!
    : :
    : : It's easy to set maxlength for the Memo component directly, but can the maximum of lines.count be set somehow? Directly or with code?
    : :
    : : Can anybody help with this?
    : :
    : The most simple way to do this is to use the OnKeyPress() event. Each time the user presses enter (#13) then check if the count has reached a cetain value. If it has, remove the keypress by changing it to a null (#0).
    :

    Hi!

    Thanks for a hint!

    I also have now found another way to solve this problem. This works for me:

    procedure TForm1.Memo1KeyPress(Sender: TObject; var Key: Char);
    var iLinesmaximum : integer;

    begin
    iLinesmaximum := 33;

    //Look! See the Memo1 Events-section: On line 'OnKeyPress'
    //there must be 'Memo1KeyPress.'

    begin
    if Key = #8 then exit; //backspace is always allowed

    if Memo1.lines.count >= iLinesmaximum then
    begin
    Key := #0;
    Showmessage('Only '+inttostr(iLinesmaximum-1)+'
    'rows is allowed!');
    end;
    end;
    end;

Sign In or Register to comment.