Tech Tip: Create a custom searchable field for 4D Write Pro
PRODUCT: 4D | VERSION: 19 | PLATFORM: Mac & Win
Published On: November 21, 2022
Currently 4D Write Pro has a Find and Replace tab for replacing text in bulk, but sometimes it is nice to have a custom searchable field that will simply highlight all the found text at once. Given a variable field Form.search for the searched text and button to find all instances of the searched text, below is the code for the button to highlight all found text:
C_OBJECT($body_o; $range_o) C_COLLECTION($found_c) // Get range that will be searched $body_o:=WP Get body(WParea) // Get collection of ranges for the found text $found_c:=WP Find all($body_o; Form.search; wk case insensitive) // If text is found, set all the found text backgrounds to yellow If ($found_c.length>0) For each ($range_o; $found_c) WP SET ATTRIBUTES($range_o; wk background color; "yellow") End for each Else // Else make all backgrounds white WP SET ATTRIBUTES(WP Text range(WPArea; wk start text; wk end text); wk background color; "white") End if |
As an example, the text "lorem" is searched in the 4D Write Pro area which would result to: