I want the user cannot write more than 12 lines

General TRichView support forum. Please post your questions here
Post Reply
armagnac
Posts: 12
Joined: Tue Mar 05, 2024 8:35 am

I want the user cannot write more than 12 lines

Post by armagnac »

As I say in the title, I want to limit the number of lines writed by the user in a TRichViewEdit.

Maybe there are different ways :
- disable KeyPress if line count > 12
- unable the rve to scroll is user want to begin a 13th line
- other idea

Thanks
Sergey Tkachenko
Site Admin
Posts: 17602
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: I want the user cannot write more than 12 lines

Post by Sergey Tkachenko »

There is no built-in line count limitation.
You can process OnChange event.

In this event, check line count:

Code: Select all

function IsParaCountOk(rv: TCustomRichView; MaxCount: Integer): Boolean;
var
  Count: Integer;
begin
  Result := False;
  Count := 0;
  for i := 0 ro rv.ItemCount - 1 do
    if rv.IsFromNewLine[i] then
    begin
      inc(Count);
      if Count > MaxCount then
        exit;
    end;
   Result := True;
end;
If not ok, call Undo.
Post Reply