delphisynedit

How to show line numbers for every 10 lines?


The SynEdit control has an event OnGutterGetText. I would like to use this to make the gutter only display every 10th line number (also line 1 and currently selected line). The same way that the Delphi (XE7) IDE works. How do I determine whether to show the line or not using this event?


Solution

  • The question transpires to be nothing to do with the edit control in reality. You simply want to know if a is an exact multiple of b. That is so if the remainder of a divided by b is zero. And the remainder operator in Delphi is mod.

    if a mod b = 0 then
    

    Now, in your case you want

    if LineNum mod 10 = 0 then
    

    This assumes that LineNum is one based. If it is zero based then you need

    if (LineNum + 1) mod 10 = 0 then