Recent

Author Topic: TSynEdit caret position on Win8.1  (Read 8145 times)

flamer0n

  • Guest
TSynEdit caret position on Win8.1
« on: March 03, 2015, 11:59:29 am »
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

  • Administrator
  • Hero Member
  • *
  • Posts: 6826
  • Debugger - SynEdit - and more
    • wiki
Re: TSynEdit caret position on Win8.1
« Reply #1 on: March 03, 2015, 12:29:43 pm »
You mean the visual placement of the caret, or the value of the properties?

flamer0n

  • Guest
Re: TSynEdit caret position on Win8.1
« Reply #2 on: March 03, 2015, 12:33:38 pm »
no not visual but the value of synEdit1.CaretX and synEdit1.CaretY

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6826
  • Debugger - SynEdit - and more
    • wiki
Re: TSynEdit caret position on Win8.1
« Reply #3 on: March 03, 2015, 12:38:36 pm »
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

  • Guest
Re: TSynEdit caret position on Win8.1
« Reply #4 on: March 03, 2015, 12:54:50 pm »
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

  • Guest
Re: TSynEdit caret position on Win8.1
« Reply #5 on: March 03, 2015, 07:13:18 pm »
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

  • Administrator
  • Hero Member
  • *
  • Posts: 6826
  • Debugger - SynEdit - and more
    • wiki
Re: TSynEdit caret position on Win8.1
« Reply #6 on: March 03, 2015, 07:26:23 pm »
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

  • Guest
Re: TSynEdit caret position on Win8.1
« Reply #7 on: March 03, 2015, 08:52:03 pm »
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

  • Guest
Re: TSynEdit caret position on Win8.1
« Reply #8 on: March 03, 2015, 09:14:58 pm »
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

  • Administrator
  • Hero Member
  • *
  • Posts: 6826
  • Debugger - SynEdit - and more
    • wiki
Re: TSynEdit caret position on Win8.1
« Reply #9 on: March 03, 2015, 09:16:46 pm »
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?

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_position

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

  • Administrator
  • Hero Member
  • *
  • Posts: 6826
  • Debugger - SynEdit - and more
    • wiki
Re: TSynEdit caret position on Win8.1
« Reply #10 on: March 03, 2015, 09:18:26 pm »
I 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

Quote
Code: [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);
« Last Edit: March 03, 2015, 09:22:02 pm by Martin_fr »

flamer0n

  • Guest
Re: TSynEdit caret position on Win8.1
« Reply #11 on: March 03, 2015, 09:32:06 pm »
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

  • Guest
Re: TSynEdit caret position on Win8.1
« Reply #12 on: March 03, 2015, 09:35:20 pm »
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

  • Administrator
  • Hero Member
  • *
  • Posts: 6826
  • Debugger - SynEdit - and more
    • wiki
Re: TSynEdit caret position on Win8.1
« Reply #13 on: March 03, 2015, 09:47:36 pm »
to 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.

Quote
I 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.

Quote
anyway, 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

  • Administrator
  • Hero Member
  • *
  • Posts: 6826
  • Debugger - SynEdit - and more
    • wiki
Re: TSynEdit caret position on Win8.1
« Reply #14 on: March 03, 2015, 09:53:24 pm »
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

Sorry, I have no idea why it may have worked before.

Also I dont know what happen in the event assigned to OnCaretPositionChanged.

 

TinyPortal © 2005-2018