Jerry Dodge
Jerry Dodge

Reputation: 27296

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?

Upvotes: -1

Views: 880

Answers (2)

Gin
Gin

Reputation: 1

{ Показываем не полные номера строк }
{ Showing incomplete line numbers   }
procedure TfrmMain.CustomGutterlinesClick(Sender: TObject);
  begin
    if CustomGutterlines1.Checked = true then
      SynEdit.OnGutterGetText := SynEditGutterGetText
    else
      SynEdit.OnGutterGetText := nil;
      SynEdit.InvalidateGutter;
    if CustomGutterlines1.Checked = false then
      // Делаем невидимым столбик с номерами
      // Making the column with numbers invisible
      SynEdit.Gutter.Visible := false
    else
      SynEdit.Gutter.Visible := true;
end;

procedure TForm1.SynEditGutterGetText(Sender: TObject; aLine: Integer; 
var aText: string);
begin
  if aLine = TSynEdit(Sender).CaretY then
    Exit;
  // Экспериментируйте ниже
  // Experiment below
  if aLine mod 10 <> 0 then 
  if aLine mod 5 <> 0 then
    aText := '-'
  else
    aText := '—';
end;
***
Reset:
  // Возвращаем значение номеров по умолчанию
  // Reset to Default
  SynEdit1.OnGutterGetText := nil;
  SynEdit1.InvalidateGutter;

Enjoy :)

1 2

Upvotes: 0

David Heffernan
David Heffernan

Reputation: 613442

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

Upvotes: 4

Related Questions