get and manipulate word/attributes at XY

  • I need ot be able to analyse attributes under the mouse cursor and obtain the word.

    I've come across CPMoveTo, which is not quite what I want. I don't want to have to physically move the caret to do this.

    I know there was no procedure for this in wpTools 4, but is there one in ver 5?

    Cheers,

    Mark

    • Offizieller Beitrag

    The function GetLineFromXY can be used.
    Please try this code in the OnMouseMove event:

    GetLineFromXY also was in V4 - but it is now much easier to extract a word - and it also works for words in headers and footers!

    Julian

  • Thanks Julian,

    Works a treat for getting word. However, can you tell me how to get the character attribute under the cursor. I tried:

    Code
    props := ActiveText.RTFProps;
        props.Attributes.GetCharAttr(par.CharAttr[posinpar ],att);
        props.AttrInterface.GetBGColor(att, clr);

    but that doesn't seem to do the job. Any ideas what I am doing wrong?

    Cheers,

    Mark

    • Offizieller Beitrag

    Example 1)

    Code
    WPRichText1.AttrHelper.CharAttr := par.CharAttr[posinpar];if WPRichText1.AttrHelper.GetFontName(f) then       Label1.Font.Name := f;


    Example 2)

    Code
    WPRichText1.AttrHelper.CharAttr := par.CharAttr[posinpar];
    if WPRichText1.AttrHelper.GetBGColor(aColor) then
           Label1.Color := aColor
    else Label1.Color := clBtnFace;

    hope this helps, Julian