 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
derRaphael
Joined: 23 Nov 2007 Posts: 841 Location: ~/.
|
Posted: Sat Dec 05, 2009 2:53 pm Post subject: [closed] assume static mode broken |
|
|
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 _________________
All scripts, unless otherwise noted, are hereby released under CC-BY
Last edited by derRaphael on Sat Dec 05, 2009 7:56 pm; edited 1 time in total |
|
| Back to top |
|
 |
Rabiator
Joined: 17 Apr 2005 Posts: 289 Location: Sauerland
|
Posted: Sat Dec 05, 2009 4:22 pm Post subject: |
|
|
Hi DerRaphael!
| Code: | | Gosub, % "StackInternal_" ( IsLabel( "StackInternal_" . Method ) ? Method : "Default" ) |
__________________________________________
Created with BBCodeWriter 7.0 - the one and only  |
|
| Back to top |
|
 |
jaco0646
Joined: 07 Oct 2006 Posts: 3113 Location: MN, USA
|
Posted: Sat Dec 05, 2009 4:24 pm Post subject: |
|
|
It looks like this line... | Code: | | Gosub, % "StackInternal_" ( IsLabel( Method ) ? Method : "Default" ) | should be: | Code: | | Gosub, % "StackInternal_" ( IsLabel( "StackInternal_" Method ) ? Method : "Default" ) |
Edit: too slow.
P.S. I moved this to Ask for Help. |
|
| Back to top |
|
 |
derRaphael
Joined: 23 Nov 2007 Posts: 841 Location: ~/.
|
Posted: Sat Dec 05, 2009 7:43 pm Post subject: |
|
|
rabiator and jaco ... thanks ....
next time i'll recheck my gosub statements
thank you both
greets
derRaphael _________________
All scripts, unless otherwise noted, are hereby released under CC-BY |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|