Jump to content
Sign in to follow this  
Aktonius

Redim deletes content of array

Recommended Posts

Aktonius

Redim deletes content of every row of 2D array once i redim it to have one more row, but if i access any content like $array[0][0] by console or just by assigning this value to some crap value just before redim then everything works fine.

I dont know why i am posting it as i will probably get "we need code" etc but this is nearly impossible to reproduce because everything works fine in a simple script, the thing is i have thousands lines of code :)

Still, what could possible be reason something like this happens?

Here is something that would work ok in normal code, but for some reason not in mine.

Func _ArrayAdd_Custom(ByRef $array, ByRef $add_array)
    Local $newsize = UBound($array) + 1

    ReDim $array[$newsize][8]
    For $column = 0 To 7
        $array[($newsize-1)][$column] = $add_array[$column]
    Next

EndFunc   ;==>_ArrayAdd_Custom
Edited by Aktonius

Share this post


Link to post
Share on other sites
Valik

Sounds like a possible copy-on-write issue. Without reliable reproducing code, though, it doesn't seem like something to worry much about.

Share this post


Link to post
Share on other sites
Aktonius

To solve this i simply changed it to

Func _ArrayAdd_Custom(ByRef $array, ByRef $add_array)
    Local $newsize = UBound($array) + 1
    Local $crapvalue

    ;WAKE UP ARRAY?!!? - after this redim wont delete content
    $crapvalue = $array[0][0]
  
    ReDim $array[$newsize][8]
    For $column = 0 To 7
        $array[($newsize-1)][$column] = $add_array[$column]
    Next

EndFunc   ;==>_ArrayAdd_Custom

Really one of weirdest issues i had with autoit, maybe calling this from wm_copydata has any connections to the problem, but then again i also tried to _array_add from dummy control, still same... Maybe it gives clues to someone with same issue one day

Edited by Aktonius

Share this post


Link to post
Share on other sites
water

What version of AutoIt do you run?

I ran the following test script and get an array with 3 rows and 8 columsn as a result:

#include <array.au3>
Global $a2D[2][8] = [["1-1", "1-2", "1-3", "1-4", "1-5", "1-6", "1-7", "1-8"],["2-1", "2-2", "2-3", "2-4", "2-5", "2-6", "2-7", "2-8"]]
Global $a2Add[8] = ["3-1", "3-2", "3-3", "3-4", "3-5", "3-6", "3-7", "3-8"]
_ArrayAdd_Custom($a2D, $a2Add)
_ArrayDisplay($a2D)

Func _ArrayAdd_Custom(ByRef $array, ByRef $add_array)
    Local $newsize = UBound($array) + 1

    ReDim $array[$newsize][8]
    For $column = 0 To 7
        $array[($newsize - 1)][$column] = $add_array[$column]
    Next

EndFunc   ;==>_ArrayAdd_Custom
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×