hi all,
probably i am simply too dumb to get it, but i have the impression, that under certain circumstences autohokey's assume static mode is broken.
here are two scripts which should do the same: build a treeview upon a defined string
working sample:
Code:
Gui,Add,TreeView,w300 h200 vMTV
Gosub, InitData
InitTree()
Gui,show,,Test Gui
Return
InitData:
struct =
(Join`n
MAIN
Title-1
Title-1_1
Title-1_2
Title-2
Title-2_1
Title-2_1_1
Title-2_1_1_1
Title-2_1_1_2
Title-2_2
Title-3
Title-3_1
Title-4
)
Return
GuiClose:
GuiEscape:
ExitApp
InitTree()
{
global
Loop,Parse,Struct,`n,`r
{
cPos := RegExMatch( A_LoopField, "(?P<Match>[^\t]+)", Level )
if ( cPos > oPos )
{
Stack_mem( cTree, "push" )
cTree := lTree
}
Else if ( cPos < oPos )
{
Loop, % oPos-cPos
cTree := stack_mem("","pop")
}
lTree := TV_Add( LevelMatch, cTree, "Expand" )
oPos := cPos
}
Return
}
stack_mem(Value = "",Method = "Default"){
Static
if ( method = "push" )
{
Stack := Value "`n" Stack
if ( Stack_Count == Stack_unset )
{
Stack_Count := 0
}
Result := ++Stack_Count
}
else if ( method = "pop" )
{
If ( Stack_Count > 0 )
{
oldStack := Stack
Stack := ""
Loop, Parse, oldStack, `n
{
If ( A_Index = 1 )
{
Result := A_LoopField
}
Else
{
Stack .= ( StrLen( Stack ) ? "`n" : "" ) A_LoopField
}
}
oldStack := ""
Stack_Count--
}
}
Return result
}
this is how it looks like:

the tree is build and its structure is intact.
the broken version:
Code:
Gui,Add,TreeView,w300 h200 vMTV
Gosub, InitData
InitTree()
Gui,show,,Test Gui
Return
InitData:
struct =
(Join`n
MAIN
Title-1
Title-1_1
Title-1_2
Title-2
Title-2_1
Title-2_1_1
Title-2_1_1_1
Title-2_1_1_2
Title-2_2
Title-3
Title-3_1
Title-4
)
Return
GuiClose:
GuiEscape:
ExitApp
InitTree()
{
global
Loop,Parse,Struct,`n,`r
{
cPos := RegExMatch( A_LoopField, "(?P<Match>[^\t]+)", Level )
if ( cPos > oPos )
{
Stack_mem( cTree, "push" )
cTree := lTree
}
Else if ( cPos < oPos )
{
Loop, % oPos-cPos
cTree := stack_mem("","pop")
}
lTree := TV_Add( LevelMatch, cTree, "Expand" )
oPos := cPos
}
Return
}
stack_mem(Value = "",Method = "Default"){
Static
Gosub, % "StackInternal_" ( IsLabel( Method ) ? Method : "Default" )
Return, % Result
StackInternal_Push:
Stack := Value "`n" Stack
if ( Stack_Count == Stack_unset )
{
Stack_Count := 0
}
Result := ++Stack_Count
Return
StackInternal_Pop:
If ( Stack_Count > 0 )
{
oldStack := Stack
Stack := ""
Loop, Parse, oldStack, `n
{
If ( A_Index = 1 )
{
Result := A_LoopField
}
Else
{
Stack .= ( StrLen( Stack ) ? "`n" : "" ) A_LoopField
}
}
oldStack := ""
Stack_Count--
}
Return
StackInternal_Default:
Result := false
Return
}
the tree is build, but its structure breaks.
due to the lack of ahk to have a proper switch behavior that imho is more flexible than pure if then else constructs i changed the stack_mem() function to work with gosubs to manage variables. but when doing so the internal stack memory (which should be static) keeps empty.
probably i just dont see my own mistake, but for me it seems that due to the internal gosubs the assume static mode breaks.
greets
derRaphael