SynMemo and bookmarks problem

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?


Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

albireo77Author Commented:

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?

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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.