Locate Value dialog box replacement

Credit:  All work done by Liz A. Woodhouse.  Feel free to send comments, suggestions, bug reports to Liz at: law@aros.net.  SEE END OF FILE FOR TERMS/DISCALIMER/COPYRIGHT.

What is it:  SEARCH.FSL and SEARCH.LSL are a dialog and code to replace the built in Locate Value dialog box invoked by pressing Ctrl+Z, and to replace the locate next function invoked by pressing Ctrl+A.

Features:  The dialog is designed to look like the built in Locate Value dialog box.  This includes hot keys and buttons.  The buttons also have 'hot keys' as follows:  Return will push the OK button, Escape will push the Cancel button and F1 will push the Help button.  (If you're using a non-English version of Paradox or Paradox's help file, see the Help button's pushButton event for instructions on localizing the code for your version.)

The field list has two options for which fields it shows.  This is determined in the cmSearch method by disabling or enabling a certain code section. The options are: either show all* fields in the table whether they show on the form or not - this is how the built in dialog works.  Or, show only those fields which are displayed on the form.  *If the field rights are 'None' under the current password, the field will not show up in the field list.  If the field is not a searchable type, it will not show up in the field list.

Either way, if the field is displayed on the form, the cursor moves to the field being searched if a match is found.  To move to the search field even if no match is found, move the relevant section of code above the if structure it's currently in.

Note: If the field is not in a record object, the option to limit the field list to those fields displayed on the form is disabled, and the option to move to the search field (if the search field is other than the target field) is also disabled.

Typing in the Field field has the following result: (in imitation of the built in dialog's behavior) Type a letter, it moves to the first field that starts with that letter, type the letter again, it moves to the next field that starts with that letter (if any), and so on until you reach the last field which starts with that letter, after the last field starting with that letter, it loops back to the first, type a different letter, it moves to the first field that starts with that letter, and so on.

Pet Peeve: This is one place where using characters other than A-Z, a-z, 0-9 in field names caused me headaches (I did some testing on a form someone else made - I wouldn't use non-alphanumeric characters in field names).  And is just one more reason why you shouldn't use non-alphanumeric characters in field names (especially spaces - which are replaced with underscores in UIObject names)!

Instructions:  To use the form and library, follow these steps.

1. Deliver SEARCH.FSL to SEARCH.FDL.

2. In SEARCH.LSL, specify the alias where SEARCH.FDL can be found (in cmSearch method, one location).

3. If you wish, copy the methods and variables declared in the SEARCH library into one of your own.

4. In the form where you wish to use these methods, do the following:
  A. Declare a logical variable named loFirst in the form's Var method
  B. In the form's open event add code to set the loFirst variable to True
  C. Declare a library variable in the form's Var method
  D. In the form's Uses method, add either the library or the cmSearch() and cmSearchNext() methods (whichever you prefer).

The syntax for the two methods would be:
Uses ObjectPAL
  cmSearch(uioTarget UIObject, loFirst Logical) Logical
  cmSearchNext(uioTarget UIObject) Logical
endUses

  E. Add code to open and close the library (where you add this is up to you, but it must be open before you invoke the search dialog).
  F. Place the following code in the form's action event:


method action(var eventInfo ActionEvent)
  var
    ;// variable to hold which field was
    ;// the target of the search command
    uioTarget UIObject
  endVar
  if eventInfo.isPreFilter() then
    ;// This code executes for each object on the form
    ;// if the user wants to search...
    if eventInfo.id() = DataSearch then
      ;//disable default
      eventInfo.setErrorCode(UserError)
      ;// get the target field
      eventInfo.getTarget(uioTarget)
      ;// if the target was a field...
      if uioTarget.Class = "Field" then
        ;// try to search the field, show error if we failed
        if not libSearch.cmSearch(uioTarget,loFirst) then
          msgStop("Error","There was a search error!")
        else
          ;// if search has no error
          ;// we've done our first search
          ;// set loFirst to false
          if loFirst = True then
            loFirst = False
          endIf
        endIf
      endIf
    endIf
    ;// if the user selects search next...
    if eventInfo.id() = DataSearchNext then
      ;// disable the default
      eventInfo.setErrorCode(UserError)
      ;// get the target field
      eventInfo.getTarget(uioTarget)
      ;// if the target was a field
      if uioTarget.Class = "Field" then
        ;// if this is the first time we've searched
        if loFirst = True then
          ;// perform a normal search
          if not libSearch.cmSearch(uioTarget,loFirst) then
            msgStop("Error","There was a search error!")
          else
            ;// if our normal search succeeds...
            loFirst = False
          endIf
        else
          ;// if this is not our first search
          ;// try to locate the next occurrence of the
          ;// search criteria
          if not libSearch.cmSearchNext(uioTarget) then
            msgStop("Error","There was a search next error!")
          endIf
        endIf
      endIf
    endIf
  else
    ;// This code executes only for the form
  endIf
endMethod


Disclaimer/Terms: This information and associated files (SEARCH.TXT, SEARCH.FSL, SEARCH.LSL) and code are provided free of charge for any legal use or activity.  Illegal use is strictly prohibited and you are solely responsible for such actions.

All files, information, and other data provided with this text file are provided as-is with no implied or explicit warranties of any kind whatsoever.  While I make good-faith efforts to provide accurate information, you should always verify my findings before incorporating this information into your own projects and processes. You are strictly and solely responsible for your use of this information. If you damage your system, data, reputation, ability to work, mental stability, or any other material (or immaterial) asset while using the information in this file or the files included with it (SEARCH.FSL and SEARCH.LSL), it is your responsibility. Practice safe computing--make a backup!

This file and the files included with it may be redistributed freely under the following terms:  All files must be included (this means: SEARCH.TXT, SEARCH.FSL and SEARCH.LSL), this file (SEARCH.TXT) may not be altered (include your own file if you wish to include additional information), you may not charge anyone any kind of fee (monetary or otherwise) for this file or its associated files, and credit must be given to the author of these files (leave the cmCredit() methods in place).

If you wish to make commercial use of this file or any of its associated files, please contact the author via the email address given at the start of this file.

Copyright 2000, Liz A. Woodhouse.  All rights reserved.
