Spotting a hyperlink?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10089
Joined: Fri Feb 19, 2010 10:17 am

Spotting a hyperlink?

Post by richmond62 » Sun May 11, 2025 6:23 pm

Let's suppose I have a text file that contains the word 'potatoes', and I read it into a textField "BigGUFF". . .

Now for every incidence of the word 'potatoes' I want to make the word 'potatoes' blue, and hyperlink it to another field called "TATTIES" so that when I click on it the content of the field "TATTIES" is loaded into the field "BigGUFF" . . .

SWEdeAndy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 324
Joined: Sat Aug 16, 2008 9:48 am
Contact:

Re: Spotting a hyperlink?

Post by SWEdeAndy » Sun May 11, 2025 8:43 pm

The styling handler:

Code: Select all

command processLinks pFieldToProcess,pWordToLinkStyle
   set the textStyle of word 1 to -1 of field pFieldToProcess to empty
   put field pFieldToProcess into tText
   
   lock screen
   put 0 into tStartSearchAt
   set the wholeMatches to true
   
   repeat
      put tokenOffset(pWordToLinkStyle, tText, tStartSearchAt) into tWordNum
      
      if tWordNum = 0 then
         exit repeat
      end if
      
      add tStartSearchAt to tWordNum
      set the textStyle of word tWordNum of field pFieldToProcess to link
      put tWordNum into tStartSearchAt
   end repeat
   
   unlock screen
end processLinks
Call it with e.g.

Code: Select all

on mouseUp
   processLinks "BigGUFF","potatoes"
end mouseUp
In the field script:

Code: Select all

on linkClicked pLink
   if pLink is among the words of the text of me then 
      answer pLink ## Insert whatever you really want it to do
   end if
end linkClicked
Andreas Bergendal
Independent app and system developer
Free LC dev tools: https://github.com/wheninspace
(WIS_WebDeployHelper, WIS_ScriptDependencies, WIS_BrowserAnimation)
WhenInSpace: https://wheninspace.com

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10044
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Spotting a hyperlink?

Post by FourthWorld » Sun May 11, 2025 8:44 pm

See the linkText property, and the linkClicked message to handle it.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply