Lazarus

Programming => Packages and Libraries => SynEdit => Topic started by: jcmontherock on November 20, 2020, 11:47:02 am

Title: SynEdit CharIndexToRowCol
Post by: jcmontherock 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.
Title: Re: SynEdit CharIndexToRowCol
Post by: Zoran 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 (https://wiki.freepascal.org/LCL_Key_Handling)
Title: Re: SynEdit CharIndexToRowCol
Post by: Martin_fr 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.
Title: Re: SynEdit CharIndexToRowCol
Post by: lucamar 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 (https://wiki.freepascal.org/LCL_Key_Handling#Keys_that_generate_KeyDown.2FChar.2FKeyUp)
Title: Re: SynEdit CharIndexToRowCol
Post by: Martin_fr 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)
Title: Re: SynEdit CharIndexToRowCol
Post by: jcmontherock 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.
TinyPortal © 2005-2018