Lazarus

Programming => LCL => Topic started by: MaxCuriosus on April 15, 2021, 05:21:16 pm

Title: Modifying the default behavior of a form containing memos
Post by: MaxCuriosus on April 15, 2021, 05:21:16 pm
1) In a form with two or more memos I'd like to reverse the roles of Tab and Crtl+Tab keystrokes,
by using Ctrl+Tab rather than Tab to navigate from a memo to another,
and by using Tab rather than Ctrl+Tab to insert a Tab character into a memo.
How can I do that?

2) Is is possible to "hard" limit the number of lines in a memo, in particular to exactly one?
Title: Re: Modifying the default behavior of a form containing memos
Post by: lucamar on April 15, 2021, 07:57:56 pm
by using Ctrl+Tab rather than Tab to navigate from a memo to another,

Isn't that the default behaviour for Ctrl+Tab?

Quote
[...] by using Tab rather than Ctrl+Tab to insert a Tab character into a memo.[...]

Set the WantTabs property to True.

Quote
2) Is is possible to "hard" limit the number of lines in a memo, in particular to exactly one?

Not that I know of but if it's only one line, why don't you use a simple TEdit?
Title: Re: Modifying the default behavior of a form containing memos
Post by: Handoko on April 15, 2021, 08:57:51 pm
This simple demo fulfill both the requests. Tested on Linux GTK2 only.

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, Forms, Controls, StdCtrls;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Memo1: TMemo;
  16.     Memo2: TMemo;
  17.     procedure FormCreate(Sender: TObject);
  18.     procedure Memo1Change(Sender: TObject);
  19.   end;
  20.  
  21. var
  22.   Form1: TForm1;
  23.  
  24. implementation
  25.  
  26. {$R *.lfm}
  27.  
  28. { TForm1 }
  29.  
  30. procedure TForm1.FormCreate(Sender: TObject);
  31. begin
  32.   Memo1.WantTabs := True;
  33.   Memo2.WantTabs := True;
  34. end;
  35.  
  36. procedure TForm1.Memo1Change(Sender: TObject);
  37. const
  38.   MaxLines = 3;
  39. begin
  40.   while Memo1.Lines.Count > MaxLines do
  41.     Memo1.Lines.Delete(Memo1.Lines.Count-1);
  42. end;
  43.  
  44. end.
Title: Re: Modifying the default behavior of a form containing memos
Post by: MaxCuriosus on April 17, 2021, 06:50:41 pm
lucamar #1,

1) By default it is Tab that allows navigation from a memo to another within the form, not Ctrl+Tab.
With "WantTabs:=true" the Tab character can be inserted either with Tab or Ctrl+Tab keystrokes, and navigation has to be done with a mouse click, which I would like to avoid.

2) You are right, for a single line TEdit is a more appropriate solution.
Title: Re: Modifying the default behavior of a form containing memos
Post by: MaxCuriosus on April 17, 2021, 06:53:51 pm
Handoko #2,

Your solution is simple enough but does not take into account the case where the last line allowed has a LineEnding character. In that case pressing Arrow-Down while the cursor is on the last allowed line will push the text upwards. Would the property "SkipLastLineBreak" be a solution and if so, how to use it?
TinyPortal © 2005-2018