#NULL wrote:Do you have any DisableDebugger anywhere in some code? Maybe the Debugger doesn't know the list if NewList was done while debugger is disabled.[/qoute]
No.
<edit>
What happens if you put EnableDebugger before CallDebugger, NewList, ListSize()?
Nothing -- see the updated image, debug and end commands are obvious ones. I get debug output for other statements, in fact, I get right before including the module, so the debugger is working...
Lord wrote:A Procedure() doesn't know List FilesFound() until
it's declared Global or Shared.
Maybe. I don't know.
You don't need to declare as global, just need to mention in the procedure it's shared.
See the updated image; I changed to global, tried w/ and w/o 'shared'
The problem is that the code doesn't get executed when run as part of the project.
When run as it's own file (not included in the project) the module works perfectly...
Paul wrote:If the simplest of modules works fine then one would have to assume you've made a mistake somewhere.
Really hard to comment when you don't post code that actually demonstrates the problem
Sorry... I really can't post the code to replicate, using the module by itself works fine. Look at the image -- "END" does not get executed when run as part of hte project, when using the exact same source file outside of hte project (ie: as main file) it works perfectly.
Here's a stripped down version.
When run as it's own source code, it works; code stops executing at "End"
when run in the project, the error occurs.
Code: Select all
EnableExplicit
;XIncludeFile "iniFileModule.pbi"
DeclareModule WatchDirOrFile
Declare WatchThread( *folder )
Declare init( cWatchFolder.s = "c:\")
EndDeclareModule
Module WatchDirOrFile
Debug "WatchDirOrFile module" ;<=- does not get executed.
EnableExplicit
EnableDebugger
Macro dbgout( txt )
Debug txt
EndMacro
Import "kernel32.lib"
ReadDirectoryChangesW(hDir, *buffer, nBufLen, bWatchSubtree, dwNotifyFilter, *bytesRetured, *Overlapped, *CompletionRoutine)
EndImport
;{ Structures
Structure FILE_NOTIFY_INFORMATION
NextEntryOffset.l
Action.l
FileNameLength.l
Filename.s{255}
EndStructure
;}
;{ Enumeration & constants
;- Constants
;{ File notify Constants
#FILE_NOTIFY_CHANGE_FILE_NAME = 1
#FILE_NOTIFY_CHANGE_DIR_NAME = 2
#FILE_NOTIFY_CHANGE_ATTRIBUTES = 4
#FILE_NOTIFY_CHANGE_SIZE = 8
#FILE_NOTIFY_CHANGE_LAST_WRITE = $10
#FILE_NOTIFY_CHANGE_LAST_ACCESS = $20
#FILE_NOTIFY_CHANGE_CREATION = $40
#FILE_NOTIFY_CHANGE_SECURITY = $100
#FILE_NOTIFY_CHANGE_ALL = $17F
#FILE_SHARE_DELETE = 4
#FILE_ACTION_ADDED = 1
#FILE_ACTION_REMOVED = 2
#FILE_ACTION_MODIFIED = 3
#FILE_ACTION_RENAMED_OLD_NAME = 4
#FILE_ACTION_RENAMED_NEW_NAME = 5
;}
;- Variables for Module
;}
Debug "Creaing list..." ;<=- does not get executed.
Global NewList FilesFound()
Debug "Created" ;<=- does not get executed.
End ;<=- does not get executed.
Define.s onedrive,googledrive,dropbox
Procedure ProcessThread( *bContinue.Byte )
;Shared FilesFound()
Protected *p
dbgout("FilesFound() processing thread started.")
Repeat
Delay(100)
CompilerIf Defined( FilesFound, #PB_List)
If ListSize( FilesFound() ) > 0 ; <=- "Linkd List not intialisd"
ForEach FilesFound()
If *bContinue\b = #False
Break
EndIf
*p = FilesFound()
Next
EndIf
CompilerElse
CompilerWarning "List FoundFiles() is not defined"
CompilerEndIf
Until *bContinue\b = #False
EndProcedure
Procedure.s addbs( str.s )
str = Trim(str)
If Right(str,1)<>"\" : str+"\" : EndIf
ProcedureReturn str
EndProcedure
Procedure WatchThread(*folder)
Protected DirectoryName.S
Protected NotifyFilter.l = #FILE_NOTIFY_CHANGE_ALL
Protected buffer.FILE_NOTIFY_INFORMATION, ovlp.OVERLAPPED
Protected FileAction_Filename.s
Protected hDir
Protected bytesRead
Protected *work.FILE_NOTIFY_INFORMATION, tmp.s, *ffbuffer
Shared FilesFound()
dbgout("Watching folder: "+DirectoryName)
hDir = CreateFile_(DirectoryName, #FILE_LIST_DIRECTORY, #FILE_SHARE_READ | #FILE_SHARE_WRITE | #FILE_SHARE_DELETE, #Null, #OPEN_EXISTING, #FILE_FLAG_BACKUP_SEMANTICS, #Null)
While ReadDirectoryChangesW(hDir, @buffer, SizeOf(FILE_NOTIFY_INFORMATION), #True, NotifyFilter, @bytesRead, @ovlp, #NUL )
;-todo: "copy *.cmd" into folder doesn't catch both files.
;-todo:
*ffbuffer = #NUL
FileAction_Filename = PeekS(@buffer\Filename, -1, #PB_Unicode)
Select buffer\Action
Case #FILE_ACTION_ADDED
dbgout("!Added: " + DirectoryName.s + FileAction_Filename)
;CopyToFolders( DirectoryName.s + FileAction_Filename )
*work = @buffer
While *work
FileAction_Filename = PeekS(@*work\Filename,-1,#PB_Unicode)
dbgout(">added "+DirectoryName+FileAction_Filename)
; CopytoFolders( DirectoryName + FileAction_Filename )
Wend
Case #FILE_ACTION_REMOVED
dbgout("Removed: " + DirectoryName.s + FileAction_Filename)
Case #FILE_ACTION_MODIFIED
dbgout("Modified: " + DirectoryName.s + FileAction_Filename)
Case #FILE_ACTION_RENAMED_OLD_NAME
;Dateiumbenennung: Alter Dateiname
dbgout("Renamed from: "+DirectoryName+FileAction_Filename)
Case #FILE_ACTION_RENAMED_NEW_NAME
;Dateiumbenennung: Neuer Dateiname
dbgout("Renamed To: "+DirectoryName+FileAction_Filename)
Default
dbgout("Unknown action: "+Str(buffer\Action) )
EndSelect
If *ffbuffer
dbgout("Adding buffer to FilesFound list")
AddElement( FilesFound() ) : FilesFound() = *ffbuffer
*ffbuffer = #NUL
EndIf
buffer\Filename = ""
Wend
EndProcedure
Procedure init( cWatchFolder.s = "c:\" )
Shared onedrive,googledrive,dropbox, FilesFound()
Static.s SpecialFolder
Static hProcessThread, hWatchThread, bStop.b = #False
dbgout("Watch/Folder init")
If IsThread( hProcessThread ) Or IsThread( hWatchThread )
dbgout("Killing old threads...")
bStop = #True : Delay(15000)
If IsThread(hProcessThread ): KillThread( hProcessThread ) : EndIf
If IsThread( hWatchThread ) : KillThread( hWatchThread ) : EndIf
EndIf
If cWatchFolder = ""
dbgout("Resetting FilesFound list ("+Str(ListSize( FilesFound()))+")")
ClearList( FilesFound() )
ElseIf FileSize( cWatchFolder ) = -2
dbgout("Watch folder: "+cWatchFolder)
If #True ;LCase(iniFile::iReadString("Misc","WatchSpecialFolder","no")) = "yes"
dbgout("Monitoring special folder: "+SpecialFolder)
hWatchThread = CreateThread( @WatchThread(), @SpecialFolder )
hProcessThread = CreateThread( @ProcessThread(), #NUL )
EndIf
EndIf
EndProcedure
init()
EndModule
CompilerIf #PB_Compiler_IsMainFile
While #True
Delay(100)
Wend
CompilerEndIf