Forum > SynEdit

SynEdit CharIndexToRowCol

(1/2) > >>

jcmontherock:
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.

Zoran:

--- Quote from: jcmontherock on November 20, 2020, 11:47:02 am ---I have another question:
How to detect "Escape" with KeyPress ?

--- End quote ---

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:

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

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:

--- Quote from: Zoran on November 20, 2020, 01:43:30 pm ---
--- Quote from: jcmontherock on November 20, 2020, 11:47:02 am ---How to detect "Escape" with KeyPress ?
--- End quote ---
You cannot. KeyPress works with characters, not with virtual key codes.
--- End quote ---

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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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

Martin_fr:
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)

Navigation

[0] Message Index

[#] Next page

Go to full version