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);
var
   bookMark: TSynEditMark;
begin
   reSourceEdit.Marks.ClearLine(Line);
   if not Assigned(Mark) then
   begin
      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;
      reSourceEdit.Marks.Place(bookMark);
      bookMark.Visible := true;
   end
   else if not Mark.IsBookmark then
   begin
      reSourceEdit.ClearBookMark(Mark.BookmarkNumber);
      reSourceEdit.Marks.Remove(Mark);
      Mark.Free;
   end;
end;

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?

Regards,
albi

albireo77Asked:
Who is Participating?

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

x
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.

HillGrooverCommented:
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);
begin
   if not Assigned(Mark) then
   begin
      Mark := TSynEditMark.Create(SynMemo1);
      Mark.Line := SynMemo1.CaretY;
      SynMemo1.Marks.Place(Mark);
      Mark.Visible := true;
   end
   else
   if not Mark.IsBookmark then
      begin
         SynMemo1.ClearBookMark(Mark.BookmarkNumber);
         SynMemo1.Marks.Remove(Mark);
         Mark.Free;
      end;
end;

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

Regards
Hill-Groover
albireo77Author Commented:
Hello,

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?

Regards,
albi
HillGrooverCommented:
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
Delphi

From novice to tech pro — start learning today.