Recent

Author Topic: SynEdit CharIndexToRowCol  (Read 3298 times)

jcmontherock

  • Full Member
  • ***
  • Posts: 235
SynEdit CharIndexToRowCol
« on: November 20, 2020, 11:47:02 am »
Hello,
I am using "CharIndexToRowCol" with SynEdit. Compiler gives me the following msg:

"CharIndexToRowCol  is deprecated: "SynMemo compatibility - very slow / SynEdit operates on x/y"

For me it works perfectly. Is a replacement for that function. I do not understand clearly what this msg means.

I have another question:
How to detect "Escape" with KeyPress ? It's work only with KeyDown.
« Last Edit: November 20, 2020, 11:49:47 am by jcmontherock »
Windows 11 UTF8-64 - Lazarus 3.2-64 - FPC 3.2.2

Zoran

  • Hero Member
  • *****
  • Posts: 1830
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: SynEdit CharIndexToRowCol
« Reply #1 on: November 20, 2020, 01:43:30 pm »
I have another question:
How to detect "Escape" with KeyPress ?

You cannot. KeyPress works with characters, not with virtual key codes. Read: https://wiki.freepascal.org/LCL_Key_Handling#What_should_be_sent_via_KeyPress

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9855
  • Debugger - SynEdit - and more
    • wiki
Re: SynEdit CharIndexToRowCol
« Reply #2 on: November 20, 2020, 01:47:31 pm »
Quote
"CharIndexToRowCol  is deprecated: "SynMemo compatibility - very slow / SynEdit operates on x/y"

There is no replacement.

SynEdit is designed to use X/Y (Char/Line position).
For quick reference read:
- https://wiki.lazarus.freepascal.org/SynEdit#Logical.2FPhysical_caret_position (Really IMPORTANT physical/logical)
- https://wiki.lazarus.freepascal.org/SynEdit#Change_text_from_code  (How to change/read text by X/Y)


Notes on CharIndexToRowCol

1) Speed is fine, when using small amount of text (a few 1000 lines). But when using CharIndexToRowCol repeatedly (e.g. in a loop) on bigger text, it becomes slow. CharIndexToRowCol loops through ALL lines up to the given position.

2) CharIndexToRowCol does not work correctly with trailing spaces, IF you have Trim-trailing-spaces active.

Otherwise CharIndexToRowCol works. So if the above is ok for you, you can use it.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: SynEdit CharIndexToRowCol
« Reply #3 on: November 20, 2020, 02:25:45 pm »
How to detect "Escape" with KeyPress ?
You cannot. KeyPress works with characters, not with virtual key codes.

In the particular case of Escape (and a few other control chars) the ASCII code is sent to KeyPress, so this should be enough in your OnKeyPress handler:

Code: Pascal  [Select][+][-]
  1. if Key = #27 then {do whatever};

ETA: As it's, in fact said in the wiki page Zoran linked to, section: Keys that generate KeyDown/Char/KeyUp
« Last Edit: November 20, 2020, 02:29:28 pm by lucamar »
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.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9855
  • Debugger - SynEdit - and more
    • wiki
Re: SynEdit CharIndexToRowCol
« Reply #4 on: November 20, 2020, 02:30:01 pm »
About escape:

If that is OnKeyDown in a SynEdit/Memo, then make sure escape is not used by SynEdit.KeyStrokes. If it is, SynEdit will catch it in KeyDown, and there will indeed be no KeyPress for it. (as for any other control sequence that SynEdit.KeyStrokes reacts to)
« Last Edit: November 20, 2020, 02:31:47 pm by Martin_fr »

jcmontherock

  • Full Member
  • ***
  • Posts: 235
Re: SynEdit CharIndexToRowCol
« Reply #5 on: November 21, 2020, 04:03:15 pm »
For Escape:
I did not find any "Escape" in the default Keystroke keys of SynEdit. Keydown event works for me.
Thanks everybody for your help.
Windows 11 UTF8-64 - Lazarus 3.2-64 - FPC 3.2.2

 

TinyPortal © 2005-2018