Modify the ABL code to ensure that:
- No excess objects are created by accident.
- Handles point to the correct object instance when calling DELETE OBJECT.
- Object instances are managed correctly. (Using widget-pools can help here)
Specific example(s):
Accidental create of object
DEFINE QUERY qCustomer FOR customer.
DEFINE VARIABLE cQueryString AS CHARACTER NO-UNDO INITIAL "".
DEFINE VARIABLE hQuery AS HANDLE NO-UNDO.
DEFINE VARIABLE iCounter AS INTEGER NO-UNDO.
ASSIGN cQueryString = "for each customer no-lock".
DO iCounter = 1 TO 10:
CREATE QUERY hQuery.
hQuery = QUERY qCustomer:HANDLE. /* reassign happens here */
hQuery:QUERY-PREPARE(cQueryString).
hQuery:QUERY-OPEN().
DELETE OBJECT hQuery.
END.
In this case the handle gets reassigned to a static query (which will get deleted when the defining procedure/class is removed, not when the DELETE OBJECT executes), so the dynamic query object never gets used or deleted.
As the code is written to re-use the static query object the CREATE QUERY and DELETE OBJECT statements are not needed at all, and can simply be removed from the code.