Ich habe ein etwas seltsames, mir nicht erklärliches Verhalten zusammen mit einem Object Array.
Basis ist ein bestehendes Object Array, aus dem ich eine TreeView fülle und das Object Array dabei erweitere ...
Code: Select all
AWS := Object()
AWS.INSERT( "X1", { Name: "AAA", Kind: "K1", Collect: "#", Group: "XXX" })
AWS.INSERT( "X2", { Name: "BBB", Kind: "K1", Collect: "#", Group: "XXX" })
AWS.INSERT( "X3", { Name: "CCC", Kind: "K1", Collect: "#", Group: "" })
AWS.INSERT( "X4", { Name: "DDD", Kind: "K2", Collect: "#", Group: "" })
Einen "Kind" und einen "Collect" Wert habe ich immer, einen "Group" Wert nicht.K1
...|- #
......|-XXX
.........|- AAA
.........|- BBB
......|-CCC
K2
...|- #
......|-DDD
Während ich den Tree aufbaue, ersetze ich mein Object Array mit allen Werten im Tree, d.h. insgesamt 9 Object Elemente, die ich jeweils mit einem "Type" (Kind, Collect, Group, Data) ergänze.
Mein Problem nun ist, das im neu generierten Object Array der "Type" bei allen identisch ist ....
Code: Select all
---------------------------
test.ahk
---------------------------
1: Collect=#, Group=XXX, Kind=K1, Name=AAA, Type=DATA <<< solte eigentlich Type=KIND sein
2: Collect=#, Group=XXX, Kind=K1, Name=AAA, Type=DATA <<< solte eigentlich Type=COLLECT sein
3: Collect=#, Group=XXX, Kind=K1, Name=AAA, Type=DATA <<< solte eigentlich Type=GROUP sein
4: Collect=#, Group=XXX, Kind=K1, Name=AAA, Type=DATA <<< OK
5: Collect=#, Group=XXX, Kind=K1, Name=BBB, Type=DATA <<< OK
6: Collect=#, Group=, Kind=K1, Name=CCC, Type=DATA <<< OK
7: Collect=#, Group=, Kind=K2, Name=DDD, Type=DATA <<< solte eigentlich Type=KIND sein
8: Collect=#, Group=, Kind=K2, Name=DDD, Type=DATA <<< solte eigentlich Type=COLLECT sein
9: Collect=#, Group=, Kind=K2, Name=DDD, Type=DATA <<< OK
---------------------------
OK
---------------------------
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance, force
; initialize object array to hold all data
AWS := Object()
; define array content
AWS := Object()
AWS.INSERT( "X1", { Name: "AAA", Kind: "K1", Collect: "#", Group: "XXX" })
AWS.INSERT( "X2", { Name: "BBB", Kind: "K1", Collect: "#", Group: "XXX" })
AWS.INSERT( "X3", { Name: "CCC", Kind: "K1", Collect: "#", Group: "" })
AWS.INSERT( "X4", { Name: "DDD", Kind: "K2", Collect: "#", Group: "" })
; create GUI
Gui, -Resize +OwnDialogs +ToolWindow +MinSize
; build the tree
Gui, Add, TreeView, x10 y10 w200 r30 +ReadOnly
GuiControl, -Redraw, treeData
TV_Delete()
AWS2Tree()
GuiControl, +Redraw, treeData
; show GUI
Gui, Show, AutoSize Center, HKHS Setup
; show AWS array content
str := ""
for indexA, itemA in AWS
{
str .= indexA . ": "
for indexB,itemB in itemA
str .= (A_Index > 1 ? ", " : "" ) . indexB . "=" . itemB
str .= "`n"
}
MsgBox, % str
Return
; close the app
GuiClose:
GuiEscape:
ExitApp
; build the treeview
AWS2Tree()
{
local key, items, TEMP
; rebuild item with new key
TEMP := AWS.Clone()
AWS := Object()
; build tree
for key, items in TEMP
AWS2TreeItem( items )
; cleanup
TEMP := ""
Return
}
AWS2TreeItem( items )
{
local pid
static sKind, sCollect, sGroup ; last used values
static pKind, pCollect, pGroup ; last used parent ids
static ID := 0
; kind change
if ( items.Kind <> sKind )
{
; kind differs, so add as parent for next items
sKind := items.Kind
pKind := TV_Add( sKind ) ; add on root
items[ "Type" ] := "KIND"
ID += 1
AWS[ ID ] := items ; add new object item wit htype KIND
sCollect := "" ; when kind change also a new collection starts
sGroup := "" ; when kind change also a new group starts
}
; collection changes
if ( items.Collect <> sCollect )
{
; collect differs, so add as parent for next items
sCollect := items.Collect
pCollect := TV_Add( sCollect, pKind ) ; add as child of KIND
items[ "Type" ] := "COLLECT"
ID += 1
AWS[ ID ] := items ; add new object item wit htype KIND
sGroup := "" ; when kind change also a new group starts
}
; group change
if (( StrLen( Trim( items.Group )) > 0 ) && ( items.Group <> sGroup ))
{
; group differs, so add as parent for next items
sGroup := items.Group
pGroup := TV_Add( sGroup, pCollect ) ; add as child of COLLECT
items[ "Type" ] := "GROUP"
ID += 1
AWS[ ID ] := items
}
; add item
if ( StrLen( Trim( items.Group )) = 0 )
pid := TV_Add( items.Name, pCollect ) ; no group, add to Collection
else if ( items.Group = sGroup )
pid := TV_Add( items.Name, pGroup ) ; group exists, add to group
items[ "Type" ] := "DATA"
ID += 1
AWS[ ID ] := items
; Return
Return
}
Verwende AHK 1.1.28.00