SynMemo and bookmarks problem

Posted on 2006-03-24
Last Modified: 2008-01-09
Hi there,

I am creating text editor using TSynMemo component from SynEdit package. I would like to use bookmark functionality. Based on SynEdit example I created OnGutterClick event as follows:

procedure TSourceEditorForm.reSourceEditGutterClick(Sender: TObject;
  Button: TMouseButton; X, Y, Line: Integer; Mark: TSynEditMark);
   bookMark: TSynEditMark;
   if not Assigned(Mark) then
      if reSourceEdit.Marks.Count > 4 then exit;
      bookMark := TSynEditMark.Create(reSourceEdit);
      bookMark.ImageIndex := reSourceEdit.Marks.Count + 9;
      bookMark.Line := reSourceEdit.CaretY;
      bookMark.Char := reSourceEdit.CaretX;
      bookMark.Visible := true;
   else if not Mark.IsBookmark then

Unfortunately it doesn't work as expected. When I click gutter line with existing bookmark it doesn't disappear. Another bookmark is created. It seems that Mark parameter in event handler is never valid. Does anyone have OnGutterClick event implemented correctly?


Question by:albireo77
    LVL 4

    Expert Comment

    Hi albi

    I'm not able to recreate your problem entirely, i think i maybe using an earlier/later version of SynEdit than you as my OnGutterClick event is different, mine doesn't have the "Button: TMouseButton;" The "Char" property doesn't exist for TSynEditMark either in my version.

    Anyway i've come up with the following which appears to work fine

    procedure TForm1.SynMemo1GutterClick(Sender: TObject; X, Y, Line: Integer; mark: TSynEditMark);
       if not Assigned(Mark) then
          Mark := TSynEditMark.Create(SynMemo1);
          Mark.Line := SynMemo1.CaretY;
          Mark.Visible := true;
       if not Mark.IsBookmark then

    basically what you've done with your code is checked to see if the variable "Mark" is assigned and if not you then create another TSynEditMark through your own variable "bookMark", the problem here is the next time you click on the gutter the program checks if "Mark" has been assigned which it hasn't and it never will be because you create "bookMark". Theoretically you should only ever get one bookmark on the entire gutter from this code, this is the problem i was getting anyway well without the Char property cause it doesn't exist but because you have the "Char" property in your version i can see why you would get more than one bookmark per line if the Char value is different for each bookmark.

    I hope this makes sense


    Author Comment


    I checked and OnGutterClick event handler without Button parameter exists in SynEdit 1.x I had 2.x After going back to 1.4 I created new OnGutterClick handler. That's very strange because whenever I click gutter and this event handler exists I get access violation exception. Even when the handler has only comment inside! So it's not bad code fault. If there is no handler, there's no exception. I created new TSynMemo completely from scratch and the situation is similar. Any ideas?

    LVL 4

    Accepted Solution

    Hi albi,

    Try removing all the .dcu files in the project directory and recompile and see what happens when you have the event in then.

    if that doesn't work search for all the .dcu files that relate to synedit and remove them then reinstall version 1.4, it could be that somewhere something related to version 2 is still lurking around.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
    Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now