Recent

Author Topic: Get the word highlighted by double-click in TMemo (Linux)  (Read 6658 times)

dkjMusic

  • Full Member
  • ***
  • Posts: 146
Get the word highlighted by double-click in TMemo (Linux)
« on: November 28, 2010, 04:48:46 pm »
I want to double-click a word in a TMemo, save the word in a string, then add the string to a TSynAnySyn's  keywords to have the word highlighted in an adjacent TSynEdit...kind of a double-click Find...

I think I can handle the stuff after finding the highlighted word in TMemo.

I found an example in Delphi, but it uses the mouse-move event with Windows procedures.
Windows 7 Ultimate/32 bit;
Lazarus 0.9.31/Rev 33300;
FPC 2.7.1/Rev 19464;
GDB 7.0.50;
(via CodeTyphon 2.30)

Tom83

  • Newbie
  • Posts: 6
Re: Get the word highlighted by double-click in TMemo (Linux)
« Reply #1 on: November 28, 2010, 05:21:27 pm »
The highlighted word of a Memo is in TMemo.SelText property.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11143
  • Debugger - SynEdit - and more
    • wiki
Re: Get the word highlighted by double-click in TMemo (Linux)
« Reply #2 on: November 28, 2010, 05:42:11 pm »

SynEdit has a special highlight mode for this:
      CurEdit.SetHighlightSearch('TheWord', []);
2nd argument, is if you want to match full words only, or use regex
      CurEdit.SetHighlightSearch('TheWord', [ssoWholeWord]);

see SynEdit.HighlightAllColor  for setting the colors of the highlight

dkjMusic

  • Full Member
  • ***
  • Posts: 146
Re: Get the word highlighted by double-click in TMemo (Linux)
« Reply #3 on: November 28, 2010, 06:31:14 pm »
The highlighted word of a Memo is in TMemo.SelText property.

Fantastic! It worked like a charm. Thanks very much.
Windows 7 Ultimate/32 bit;
Lazarus 0.9.31/Rev 33300;
FPC 2.7.1/Rev 19464;
GDB 7.0.50;
(via CodeTyphon 2.30)

dkjMusic

  • Full Member
  • ***
  • Posts: 146
Re: Get the word highlighted by double-click in TMemo (Linux)
« Reply #4 on: November 28, 2010, 06:36:14 pm »

SynEdit has a special highlight mode for this:
      CurEdit.SetHighlightSearch('TheWord', []);
2nd argument, is if you want to match full words only, or use regex
      CurEdit.SetHighlightSearch('TheWord', [ssoWholeWord]);

see SynEdit.HighlightAllColor  for setting the colors of the highlight

How do I use this? I tried

SynEdit1.CurEdit.SetHighlightSearch(Memo2.SelText, [ssoWholeWord]);

but got compiler errors: unit1.pas(44,14) Error: identifier idents no member "CurEdit"
and unit1.pas(44,69) Error: Identifier not found "ssoWholeWord"

Never mind. I used
SynEdit1.SetHighlightSearch(Memo2.SelText, []);
and everything worked as desired.
« Last Edit: November 28, 2010, 07:02:47 pm by dkjMusic »
Windows 7 Ultimate/32 bit;
Lazarus 0.9.31/Rev 33300;
FPC 2.7.1/Rev 19464;
GDB 7.0.50;
(via CodeTyphon 2.30)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11143
  • Debugger - SynEdit - and more
    • wiki
Re: Get the word highlighted by double-click in TMemo (Linux)
« Reply #5 on: November 28, 2010, 11:41:30 pm »
Sorry copy and paste:
CurEdit = SynEdit

SynEdit1.SetHighlightSearch(Memo2.SelText, [ssoWholeWord]);

It's always only one word (and all occurences of that word) => once you set the next word, the previous word is lost.

IIRC it also has a different priority to SynAnySyn compared to highlighing the selected block (blue selection highlight)

SetHighlightSearch goes over the blue-selection, while SynAnySyn goes under the selection.


 

TinyPortal © 2005-2018