KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Helper Method to locate and open method for editing
PRODUCT: 4D | VERSION: 14.3 | PLATFORM: Mac & Win
Published On: August 14, 2015

Have you ever been in a situation where you need to modify a method, you know exactly what the method is named (or at least you know some of the method name), but you simply cannot find the method in the list of methods? If this sounds familiar then the following method may be just what you have been looking for!

This method is designed to help you locate methods in your structure by name, even if you only know part of the name! The goal here is to help narrow down the search until you have only 1 result; once there is only 1 result the method found is opened in the method editor.

Here is the code:

// _HELP_find_and_edit_method

C_LONGINT($numMethodsFound_li)
ARRAY TEXT($method_names_at;0)
C_TEXT($matching_t;$result_t)
$matching_t:=Request("Enter part of a method name to search for")
if(OK=1)
METHOD GET NAMES($method_names_at;"@"+$matching_t+"@")
$numMethodsFound_li:=Size of array($method_names_at)
Case of
   : ($numMethodsFound_li=0)
    // no methods found mathcing the search term
   ALERT("no method found matching the search term")
   : ($numMethodsFound_li=1)
    // single method found, open it
   METHOD OPEN PATH($method_names_at{1})
   : (($numMethodsFound_li>1) & ($numMethodsFound_li<11))
    // more than 1 & less than 11 method found matching the search term
   $result_t:=JSON Stringify array($method_names_at;*) // quickly get array into text
   $result_t:=Substring($result_t;3;Length($result_t)-3) // remove [ and carriage return new line
   ALERT("found "+String($numMethodsFound_li)+" methods matching the search term:\r\n"+$result_t)
   : ($numMethodsFound_li>10)
    // more than 10 methods found matching the search term
   $result_t:=JSON Stringify array($method_names_at) // quickly get array to text
   $result_t:=Replace string($result_t;"[";"") // remove [
   $result_t:=Replace string($result_t;"]";"") // remove ]
   $result_t:=Replace string($result_t;",";", ") // add a space after each comma
   ALERT("found "+String($numMethodsFound_li)+" methods matching the search term:\r\n"+$result_t)
End case
End If


When the method is executed the following request box is displayed:


Using a @ wildcard symbol is not necessary because the serch term is already encapsulated in @ wildcards to make this a 'contains' search:


If exactly 1 method is found matching the search term it is opened within the Method Editor using the METHOD OPEN PATH command.

If no methods are found matching that search term a dialog is presented stating that:


If there are more than 1 methods found matching the search term they are displayed in an alert like this:


If there are more than 10 methods found matching the search term they are displayed in an alert like this:


This approach could be improved upon but should be helpful if you want to quickly find and edit a method (and even more helpful if you are having trouble locating the method).