Kbase 15780: EXAMPLE: Seek record in a browse as user types into fill-in
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  5/10/1998 |
|
EXAMPLE: Seek record in a browse as user types into fill-in
This code example shows how a programmer might use a fill-in and
browse together to create a "record seek" capability. An ANYKEY
trigger on the fill-in serves to capture keypresses by the user.
A separate record FIND is carried out, and if successful the browse
is repositioned to that same record.
This approach can be further modified so that the seek takes place
as the user types into the browse itself, with no fill-in. This
example does not include this functionality, however programmers are
invited to experiment with this modification on their own. Note
that without a fill-in to retain what has been typed so far, a
mechanism would have to be created to keep track of what the user
has input. This might be accomplished with a dummy variable
to serve as a substitute for the fill-in.
Another caveat should be mentioned. When incorporating this
code into an actual application, programmers should be careful
to make sure the FIND used in the ANYKEY trigger does not succeed
in finding a record that isn't actually included in the browse's
result list. Otherwise, an error will result when trying to
reposition the browse. Programmers are invited to enhance the
example in this regard as well.
Requirements:
(1) A variable defined as RECID.
DEF VAR r AS RECID.
(2) A browse with an associated query. In this example, the
query will be FOR EACH customer BY name.
DEF BROWSE cust-browse QUERY cust-browse NO-LOCK DISPLAY
Customer.Name Customer.Cust-num WITH SIZE 65 BY 10.
OPEN QUERY cust-browse FOR EACH customer NO-LOCK BY name.
(3) A fill-in to serve as a place for the user to type in the
character string to be used in the "seek". As each letter
is typed, the browse will automatically reposition to the
customer whose name begins with the letters as they appear in
the fill-in.
(4) An ANYKEY trigger on the fill-in.
ON ANYKEY OF fill-in-1 IN FRAME frame-a DO:
APPLY LASTKEY.
FIND FIRST customer WHERE customer.name BEGINS
fill-in-1:SCREEN-VALUE NO-LOCK NO-ERROR.
IF AVAILABLE(customer) THEN DO:
r = RECID(customer).
REPOSITION cust-browse TO RECID r.
END.
RETURN NO-APPLY.
END.
Important highlights of the ANYKEY trigger include:
- an APPLY LASTKEY which makes sure the FIND will take into
account what the user has just typed, whether it be an
alphanumeric or a backspace/delete.
- a FIND that is done with NO-LOCK and NO-ERROR.
- a REPOSITION that takes place only if the FIND has been
successful.
- a RETURN NO-APPLY to bypass the fill-in's default behavior
of applying the lastkey. Without this statement the
user's input would appear twice, once due to the APPLY
LASTKEY executed and once due to default behavior.
This example is supplied for informational purposes only.
Progress Software Technical Support Note # 15780