Recent

Author Topic: Modifying the default behavior of a form containing memos  (Read 982 times)

MaxCuriosus

  • Full Member
  • ***
  • Posts: 136
Modifying the default behavior of a form containing memos
« 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?

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Modifying the default behavior of a form containing memos
« Reply #1 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?
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: Modifying the default behavior of a form containing memos
« Reply #2 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.

MaxCuriosus

  • Full Member
  • ***
  • Posts: 136
Re: Modifying the default behavior of a form containing memos
« Reply #3 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.

MaxCuriosus

  • Full Member
  • ***
  • Posts: 136
Re: Modifying the default behavior of a form containing memos
« Reply #4 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