Author | Topic: Error when load array | |
---|---|---|
Jorge L | Error when load array on Wed, 03 Oct 2012 12:12:10 -0300 Hello to all I cannot understand that it happens with this example, if the mistake is mine or of xbase When I load the array in the 2nd FOR, it me loads the remaining elements please, can you helpme ? thanks and regards Arreglos.prg arreglos.xpj | |
Jorge L | Re: Error when load array on Mon, 29 Oct 2012 12:00:19 -0300 Hi If i initialize the array with afill( aaux, {} ), the content of all the subarray, they are unified, surely for the managing for reference of the variable But if i initialize with a for - next, i don't have problems, the behavior of every subarray is independent Regards "Jorge L" escribió en el mensaje de noticias:5135ce10$1126e3f0$3a68f@news.alaska-software.com... Hello to all I cannot understand that it happens with this example, if the mistake is mine or of xbase When I load the array in the 2nd FOR, it me loads the remaining elements please, can you helpme ? thanks and regards | |
Richard Hankins | Re: Error when load array on Mon, 29 Oct 2012 11:09:27 -0500 On Mon, 29 Oct 2012 12:00:19 -0300, Jorge L wrote: > Hi > > If i initialize the array with afill( aaux, {} ), the content of all the > subarray, they are unified, surely for the managing for reference of the > variable > > But if i initialize with a for - next, i don't have problems, the behavior > of every subarray is independent > > Regards > > "Jorge L" escribió en el mensaje de > noticias:5135ce10$1126e3f0$3a68f@news.alaska-software.com... > > Hello to all > > I cannot understand that it happens with this example, if the mistake is > mine or of xbase > > When I load the array in the 2nd FOR, it me loads the remaining elements > > please, can you helpme ? > > thanks and regards Jorge, Initialize the array with the following: aAux := Array(8,0) That will resolve all of your issues. If you use aFill(...,{}) it will point all elements to the same section of memory. By using array(8,0) it knows to create a new block of memory for each sub element of the array. | |
Jorge L | Re: Error when load array on Mon, 29 Oct 2012 14:27:09 -0300 Thank you richard ! "Richard Hankins" escribió en el mensaje de noticias:1qzuxamoa0h3p.1l6832nz5nuvj.dlg@40tude.net... On Mon, 29 Oct 2012 12:00:19 -0300, Jorge L wrote: > Hi > > If i initialize the array with afill( aaux, {} ), the content of all the > subarray, they are unified, surely for the managing for reference of the > variable > > But if i initialize with a for - next, i don't have problems, the behavior > of every subarray is independent > > Regards > > "Jorge L" escribió en el mensaje de > noticias:5135ce10$1126e3f0$3a68f@news.alaska-software.com... > > Hello to all > > I cannot understand that it happens with this example, if the mistake is > mine or of xbase > > When I load the array in the 2nd FOR, it me loads the remaining elements > > please, can you helpme ? > > thanks and regards Jorge, Initialize the array with the following: aAux := Array(8,0) That will resolve all of your issues. If you use aFill(...,{}) it will point all elements to the same section of memory. By using array(8,0) it knows to create a new block of memory for each sub element of the array. | |
Thomas Braun | Re: Error when load array on Tue, 30 Oct 2012 08:34:49 +0100 Jorge L wrote: > Hi > > If i initialize the array with afill( aaux, {} ), Think of afill like this: FUNCTION afill( aArray, xValue ) LOCAL nI FOR nI := 1 TO LEN(aArray) aArray[nI] := xValue NEXT RETURN aArray This is why every element of aaux holds the same reference to the empty array {} Use either the method Richard wrote or your own for...next loop Thomas |