WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Arrays
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

PtrPersistent and ArrInitialize Issue

 Keywords:  PtrPersistent ArrInitialize Pointer

Question:

Started playing around with "ptrPersistent". Wanted to keep some information in an array. Got a rather strange result. Here is the code, distilled down to a minimum.
#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?

Answer:

The problem resides in the 'ArrInitialize' function and can be reproduced in 2009B. It will be addressed in the next release.

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