Lazarus

Programming => Packages and Libraries => SynEdit => Topic started by: snorkel on March 16, 2013, 04:15:15 am

Title: Synedit question
Post by: snorkel on March 16, 2013, 04:15:15 am
Hi,
I need to get the previous token from the current caret position, is there a way to do this?

I found a NextToken function but no previous one.

Thanks
Title: Re: Synedit question
Post by: Martin_fr on March 16, 2013, 04:34:52 am
from the sources:
Code: [Select]
    function NextTokenPos: TPoint; virtual; deprecated; // use next word pos instead
    function NextWordPos: TPoint; virtual;
    function PrevWordPos: TPoint; virtual;

You shouldn't use NextTokenPos as it is deprecated.

But if you need to stick to highlighter tokens, instead of words, then there is no such function.

What do you need it for?
Title: Re: Synedit question
Post by: snorkel on March 18, 2013, 05:44:25 pm
Hi Martin,
What I want to do is when the user types something like this:

select * from te <---then hits ctrl space I want to detect if the last word is from,update or into and then fill the completion list with the table names from the sqlite database.

I have it kind of working by testing if the current completion text <> '' then subtracting the length of the current completion text - caretX so I can call getprevword and check if it's one of the keywords for tables.  If I don't move the caret back a bit getprevword grabs whatever the user entered prior to hitting ctrl+space.

Thanks :-)
Title: Re: Synedit question
Post by: Martin_fr on March 18, 2013, 07:15:28 pm
Yes, for that you should use the word functions. You also have

    procedure GetWordBoundsAtRowCol(const XY: TPoint; out StartX, EndX: integer);
    function GetWordAtRowCol(XY: TPoint): string;
TinyPortal © 2005-2018