Kbase P99087: Errors 142 & 3131 when dynamic buffer field is assigned to by dynamic-function
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  12/21/2004 |
|
Status: Unverified
SYMPTOM(s):
Using dynamic buffer to update a record
The new value for the field being changed is determined by a dynamic-function call to a function which is passed the handle of the buffer being modified
** Unable to update <filename> Field. (142)
Unable to set attribute <attribute name> in widget <widget name> of type <widget-type>. (3131)
CAUSE:
The dynamic function which is called during the assignment actually uses the buffer handle which is passed to it (and which points to the record being modified) to create a new dynamic query and to then walk through the records (which actually causes the record we are in the middle of modifying to be swapped out for a different record).
FIX:
Modify the code in the dynamic function so that it creates a new dynamic buffer based in the buffer handle that is passed in as a parameter. Ensure that the BUFFER-NAME phrase of the CREATE BUFFER statement is used to give the dynamic buffer a different name than the buffer handle has.
The following sample code shows how to walk through the records in the table that the input buffer handle parameter points to without accidentally changing the current record that is being assigned to:
FUNCTION getNewCreditLimit RETURNS DECIMAL (hBuffer AS HANDLE).
DEFINE VARIABLE hQuery AS HANDLE NO-UNDO.
DEFINE VARIABLE hQueryBuf AS HANDLE NO-UNDO.
CREATE QUERY hQuery.
CREATE BUFFER hQueryBuf FOR TABLE hBuffer BUFFER-NAME 'AlternateBufferNameGoesHere'.
hQuery:SET-BUFFERS(hQueryBuf).
hQuery:QUERY-PREPARE('FOR EACH AlternateBufferNameGoesHere').
hQuery:QUERY-OPEN().
hQuery:GET-FIRST().
DO WHILE NOT hQuery:QUERY-OFF-END:
hQuery:GET-NEXT().
END.
hQuery:QUERY-CLOSE().
DELETE OBJECT hQuery.
DELETE OBJECT hQueryBuf.
RETURN 1234.56. /* This hard coded value is just for sample purposes, real code would do something useful */
END FUNCTION.