TSynEdit caret position on Win8.1 lazarus / 69-SynEdit ---------------------------------------------------------------------- flamer0n · 2015-03-03 10:59 1. compiled sources on Win8.1 64bit using Lazarus 1.4RC2 (32bit), and noticed that TSynEdit CaretX has CaretY value and vice versa 2. compiled the same sources on Win7 64bit using Lazarus 1.4RC2 (32bit) and TSynEdit caret position values are normal (so X is X and Y is Y) ---------------------------------------------------------------------- Martin_fr · 2015-03-03 11:29 You mean the visual placement of the caret, or the value of the properties? ---------------------------------------------------------------------- flamer0n · 2015-03-03 11:33 no not visual but the value of synEdit1.CaretX and synEdit1.CaretY ---------------------------------------------------------------------- Martin_fr · 2015-03-03 11:38 did you "clean all" before building? Doel this only apply to CaretX / CaretY or also to CaretXY.x /CaretXY.y and/or LogiralCaret(X) ? -------------- Which level of optimization did you apply? Does it happen with -O- or -O1 ? ---------------------------------------------------------------------- flamer0n · 2015-03-03 11:54 i didn't clean before building, it was a new separate install of lazarus 1.4rc2 on my win8.1 machine, I installed components  I needed  from a location to be used only with rc2 and then compiled the sources. I didn't check anything else but my code thinking I made a mistake somewhere (line 291 and 347 here https://github.com/flakron- shkodra/LazSqlX/blob/master/LazSqlXCtrls/LazSqlXCtrls.pas which gets CaretX and CaretY  and reports it onchange and keyup), but today I compiled sources on my win7 machine (also with new separate rc2 installation) without any modification of the source and it behaves normal. I don't know what happens with caretxy and logicalCaret(x) or y because I didn't check them but I can check them later because currently I'm on win7 and here it works normal ---------------------------------------------------------------------- flamer0n · 2015-03-03 18:13 Ok now I'm on win8.1; did a cleanup of built units and packages that project uses, and started debugging, checked the values of CaretXY.X and Y; Also LogicalCaretXY.X and .Y, the values are swapped, meaning wrong. ---------------------------------------------------------------------- Martin_fr · 2015-03-03 18:26 This is very odd. My current guess would be something goes wrong during compilation. The values do (afaik) not depend on any system call, so I do not see how this can be OS dependent. It is the same revision of fpc? What optimization level? And did you try -O- or -O1 ? Also try to manually clean all .ppu and .o files from the SynEdit folder and from your project / your package.  And check there is nowhere else a Syn*.ppu (unless a unit exists for it). ---------- Otherwise check in the debugger:   YourSynEdit.FCaret It has     FLinePos: Integer;     // 1 based     FCharPos: Integer;     // 1 based     FBytePos, FBytePosOffset: Integer;     // 1 based FLinePos should always be valid. FChar and FBytePos: One of them should be valid. (FChar is physical, FByte is Logical) ---------------------------------------------------------------------- flamer0n · 2015-03-03 19:52 Compilation and Linking: -O1 and nothing else Debugging: Dwarf with sets (using external gdb file) , -Ct (StackTrace) checked and nothing else that's all in project options Manually deleted .ppu and .o in components\synedit\units\{targetOs} Looking at FCaret in debugging I see FLinePos is correct and FCharPos looks good too. What confuses me is CaretX returning CharPos and CaretY returning LinePos this is from SynEdit unit Code: [Select]function TCustomSynEdit.GetCaretX : Integer; begin   Result:= FCaret.CharPos; end; function TCustomSynEdit.GetCaretY : Integer; begin   Result:= FCaret.LinePos; end;  Is that how it should be? ---------------------------------------------------------------------- flamer0n · 2015-03-03 20:14 I connected remotely to the pc in my workplace (win7) and looked at the code in SynEdit,it was same as I posted above; did a cleanup there and after that code behaves just as same as in Win8.1 where I'm currently working. So.. now we have same results on both machines but I'm still puzzled why I didn't see that before compiling with Lazarus 1.4RC2... I'm pretty sure it was the other way round before this new installation, I mean CaretX returned what I undestood the current Line on SynEdit, that's how it worked ---------------------------------------------------------------------- Martin_fr · 2015-03-03 20:16 Quote from: flamer0n on March 03, 2015, 08:52:03 pmLooking at FCaret in debugging I see FLinePos is correct and FCharPos looks good too. What confuses me is CaretX returning CharPos and CaretY returning LinePos this is from SynEdit unit Code: [Select]function TCustomSynEdit.GetCaretX : Integer; begin   Result:= FCaret.CharPos; end; function TCustomSynEdit.GetCaretY : Integer; begin   Result:= FCaret.LinePos; end;  Is that how it should be? Yes, or why would it not be ? y is the line in text, so it should be "FCaret.LinePos" "CharPos" is badly named though. It is the "physical pos". - That is the position in "char-cells" on the screen. - That is NOT the position in chars (SynEdit does not provide a position in chars.) BytePos is "logical" That is in byte. http://wiki.lazarus.freepascal.org/SynEdit#Logical.2FPhysical_caret_po sition So If your text is as below. With tab "--->" (tabwidth = 6) and each letter of äöü has 2 bytes: äöü-->mno Then "m" (or rather the caret pos in front of "m") is - logical x = 8 - physical x = 7 even though "m" is the 5th char ---------------------------------------------------------------------- Martin_fr · 2015-03-03 20:18 Quote from: flamer0n on March 03, 2015, 09:14:58 pmI mean CaretX returned what I undestood the current Line on SynEdit, that's how it worked X is NOT the line, at least should not be. X is horizontal / Y vertical --- EDIT QuoteCode: [Select] TLazSqlXCaretPositionChanged = procedure (Line, Column : Integer) of object; Code: [Select] FOnCaretPositionChanged(FQueryEditor.CaretX,FQueryEditor.CaretY); That is wrong. If you want line first, then you need Code: [Select] FOnCaretPositionChanged(FQueryEditor.CaretY,FQueryEditor.CaretX); ---------------------------------------------------------------------- flamer0n · 2015-03-03 20:32 to clear up this confusion, X is returning Vertical and Y is returning Horizontal (but I think you already know that) and when talking about lines for example of a Tmemo or in this case TSynEdit  I always think of rows meaning horizontal lines(ie CurrentLine IS NOT the CurrentCharPos) ...anyway, SynEdit behaved differently in 1.2.6 ---------------------------------------------------------------------- flamer0n · 2015-03-03 20:35 It's ok if it's wrong,easy to fix, my fault ok? But I just want to know why it wasn't before I compiled it with 1.4RC2. I got versions of LazSqlx both builds and source codes, and you can see that that part of code never changed ever since it was introduced ---------------------------------------------------------------------- Martin_fr · 2015-03-03 20:47 Quote from: flamer0n on March 03, 2015, 09:32:06 pmto clear up this confusion, X is returning Vertical and Y is returning Horizontal When you press the cursor up/down key, which value changes? Cursor up/down key *should* change CaretY. If it does not some debugging is needed. QuoteI always think of rows meaning horizontal lines "horizontal lines" yes, but vertical movement => Y Ok this is getting more confusing. Lets stick to looking at the cursor keys up/down. Quote(ie CurrentLine IS NOT the CurrentCharPos) CurrentLine is a string. CurrentCharPos is the left/right position *in* this string. ("physical"!, so neither in bytes nor in chars). CurrentCharPos is *NOT* the number of the line/row. Quoteanyway, SynEdit behaved differently in 1.2.6 I dont know why that would be the case. I am sure the code for caretx/y has not changed. Look at the code that I quoted from your file. You pass "CaretX" as value for param "Line". That is wrong. Correct is "CaretY" as param "Line". CaretY = Row or Line. (At least it should be) ---------------------------------------------------------------------- Martin_fr · 2015-03-03 20:53 Quote from: flamer0n on March 03, 2015, 09:35:20 pmIt's ok if it's wrong,easy to fix, my fault ok? But I just want to know why it wasn't before I compiled it with 1.4RC2. I got versions of LazSqlx both builds and source codes, and you can see that that part of code never changed ever since it was introduced Sorry, I have no idea why it may have worked before. Also I dont know what happen in the event assigned to OnCaretPositionChanged. ---------------------------------------------------------------------- Martin_fr · 2015-03-03 20:56 Btw: LineText = SynEdit.Lines[SynEdit.CaretY - 1] CaretY starts at 1 Lines[] start at 0 ---------------------------------------------------------------------- flamer0n · 2015-03-03 21:09 I get it. However it was, I'm glad to know that CaretY is actually the Line, I hope it remains the same in the future releases or I'll stick to same version of lazarus until i die