Kbase P21664: MEMPTR size is retained from the first call to a procedure t
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  3/20/2003 |
|
Status: Unverified
SYMPTOM(s):
MEMPTR size does not change from the first call to the procedure that defines it.
Running code like similar to the following, the MEMPTR size variable mBuffer retains the size allocated it in the first call to the procedure pTestMessage:
DEFINE VARIABLE cMessage AS CHARACTER NO-UNDO.
DEFINE VARIABLE iCounter AS INTEGER NO-UNDO.
DO iCounter = 100 TO 300 BY 100:
cMessage = FILL("x", iCounter).
RUN pTestMessage(INPUT cMessage).
END.
PROCEDURE pTestMessage:
DEFINE INPUT PARAMETER cMessage AS CHARACTER NO-UNDO.
DEFINE VARIABLE mBuffer AS MEMPTR NO-UNDO.
DEFINE VARIABLE iLength AS INTEGER NO-UNDO.
ASSIGN
iLength = LENGTH(cMessage)
SET-SIZE(mBuffer) = iLength.
MESSAGE
"Message Length: " "~t" iLength
"Buffer Size: " "~t" GET-SIZE(mBuffer)
VIEW-AS ALERT-BOX INFO BUTTONS OK.
END PROCEDURE.
CAUSE:
To resize the memory allocated to a MEMPTR variable, invoke SET-SIZE = 0 before invoking SET-SIZE with an expression equal to the new size allocation value.
If the specified size is greater than 0 and memptr-var is fully initialized, the SET-SIZE statement has no effect and leaves memptr-var unchanged.
FIX:
DEFINE VARIABLE cMessage AS CHARACTER NO-UNDO.
DEFINE VARIABLE iCounter AS INTEGER NO-UNDO.
DO iCounter = 100 TO 300 BY 100:
cMessage = FILL("x", iCounter).
RUN pTestMessage(INPUT cMessage).
END.
PROCEDURE pTestMessage:
DEFINE INPUT PARAMETER cMessage AS CHARACTER NO-UNDO.
DEFINE VARIABLE mBuffer AS MEMPTR NO-UNDO.
DEFINE VARIABLE iLength AS INTEGER NO-UNDO.
ASSIGN
SET-SIZE(mBuffer) = 0 /*** Add this statement ***/
iLength = LENGTH(cMessage)
SET-SIZE(mBuffer) = iLength.
MESSAGE
"Message Length: " "~t" iLength
"Buffer Size: " "~t" GET-SIZE(mBuffer)
VIEW-AS ALERT-BOX INFO BUTTONS OK.
END PROCEDURE.