AutoHotkey Community

It is currently May 27th, 2012, 12:22 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: December 5th, 2009, 3:53 pm 
Offline

Joined: November 23rd, 2007, 10:23 am
Posts: 841
Location: ~/.
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:

Image

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
}


Image

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

_________________
Image
    All scripts, unless otherwise noted, are hereby released under CC-BY


Last edited by derRaphael on December 5th, 2009, 8:56 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 5th, 2009, 5:22 pm 
Offline

Joined: April 17th, 2005, 7:47 pm
Posts: 289
Location: Sauerland
Hi DerRaphael!
Code:
   Gosub, % "StackInternal_" ( IsLabel( "StackInternal_" . Method ) ? Method : "Default" )
:wink:
__________________________________________
Created with BBCodeWriter 7.0 - the one and only :D


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 5th, 2009, 5:24 pm 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 5th, 2009, 8:43 pm 
Offline

Joined: November 23rd, 2007, 10:23 am
Posts: 841
Location: ~/.
rabiator and jaco ... thanks .... :oops:

:) next time i'll recheck my gosub statements

thank you both

greets
derRaphael

_________________
Image
    All scripts, unless otherwise noted, are hereby released under CC-BY


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Leef_me, rjgatito, Scratch, XstatyK, Yahoo [Bot] and 22 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group