Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: PtrPersistent ArrInitialize Pointer
#DefineFunction Test(Param1,Param2) pInteger = PtrPersistent(pInteger,0) pString = PtrPersistent(pString,"") pArray = PtrPersistent(pArray,0) if *pInteger == 0 *pArray = ArrDimension(8) ArrInitialize(*pArray,0) *pInteger = 1 end if return "" #EndFunction Test("A","B")I was getting strange errors when I ran this, so I stepped through the execution with WinBatch Studio. When the script executes ArrInitialize(*pArray,0), studio shows the pString value has become an array. This is certainly not what I expected.
Minor changes in the script can change the behavior. For example, if the function has three parameters, instead of two, the "pInteger" value becomes an array. (Still not what I expected!)What's going on here?
In the interim a workaround is to create and initialize the array in a temporary variable then assign the temporary variable to the pointer
#DefineFunction Test(Param1,Param2) DebugTrace(@ON, DirScript():"Dump.txt") pInteger = PtrPersistent(pInteger,0) pString = PtrPersistent(pString,"") pArray = PtrPersistent(Array,0) If *pInteger == 0 aTemp = ArrDimension(8) ArrInitialize(aTemp,0) *pArray = aTemp *pInteger = 1 EndIf Return "" #EndFunction Test("A","B")Thanx for reporting the problem. DON'T PANIC
Article ID: W17664
Filename: PtrPersistent and ArrInitialize Issue.txt
File Created: 2009:05:04:14:47:24
Last Updated: 2009:05:04:14:47:24