[solved] Is it bug or just me
Posted: Thu Dec 26, 2024 2:53 am
Hi All, happy seasons greetings.
I've been coding in PB for some time, mostly my own code, but recent version update broke lots of my code in ways I can not find, and have had to go backwards and compile with old version in same cases.. because I could not find whwre the problem was..
Then a few days back I tried a simple experiment and it failed too, so here is that code which breaks on multiple versions in diffirent ways.
Please let me know what you find and what I'm doing wrong here.
Thanks
JAL
I've been coding in PB for some time, mostly my own code, but recent version update broke lots of my code in ways I can not find, and have had to go backwards and compile with old version in same cases.. because I could not find whwre the problem was..
Then a few days back I tried a simple experiment and it failed too, so here is that code which breaks on multiple versions in diffirent ways.
Code: Select all
EnableDebugger
; Test Code
; ERRORS when using non-hardwired parameters in call to ExamineDirectory()
; code based on code from PB-HELP, only save result to variable is different.
; Breaks on call to NextDirectoryEntry() in compiled or in debug mode
; only happens when using NON hardwired numbers like ExamineDirectory(0)
; Set #TEST_CODE constant below to either 1, 2, 3 or 4, then compile run with Debugger
;#TEST_CODE = 1 ; Works as expected, as per help file
#TEST_CODE = 2 ; Using #PB_Any, produces ERROR
;#TEST_CODE = 3 ; use a constant, produces ERROR
;#TEST_CODE = 4 ; use a variable
;; RESULTS
;;
;;; >>> [ERROR] The specified #Directory is not initialised.
;;
; Tried this in different version of PureBasic
;; PureBasic 6.04 LTS (Windows - x64)
;; WORKS for #TEST_CODE = 1 & 2
;; Will Break for #TEST_CODE = 3 & 4
;; PureBasic 6.12 LTS (Windows - x64)
;; WORKS for #TEST_CODE = 1 ONLY
;; Breaks for every other case #TEST_CODE = 2, 3 & 4
Directory$ = GetHomeDirectory() ; Lists files in the home directory
CompilerIf #TEST_CODE = 1
; from help file, only save to var lDir is change, else all same.
; ### THIS WORKS ####
lDir.l = ExamineDirectory(0, Directory$, "*.test")
If lDir
While NextDirectoryEntry(0)
If DirectoryEntryType(0) = #PB_DirectoryEntry_File
Type$ = "[File] "
Size$ = " (Size: " + DirectoryEntrySize(0) + ")"
Else
Type$ = "[Directory] "
Size$ = "" ; A directory doesn't have a size
EndIf
Debug Type$ + DirectoryEntryName(0) + Size$
Wend
FinishDirectory(0)
EndIf
CompilerEndIf
CompilerIf #TEST_CODE = 2
; >>>> NOTE using #PB_Any
lDir.l = ExamineDirectory(#PB_Any, Directory$, "*.test")
If lDir
While NextDirectoryEntry(lDir)
If DirectoryEntryType(lDir) = #PB_DirectoryEntry_File
Type$ = "[File] "
Size$ = " (Size: " + DirectoryEntrySize(lDir) + ")"
Else
Type$ = "[Directory] "
Size$ = "" ; A directory doesn't have a size
EndIf
Debug Type$ + DirectoryEntryName(lDir) + Size$
Wend
FinishDirectory(lDir)
EndIf
CompilerEndIf
CompilerIf #TEST_CODE = 3
; declare a constant instead of #PB_Any
; NOTE: It could be any vaild variable here, too it breaks
Enumeration
#TEST_DIR_SEARCH
EndEnumeration
; >>>> NOTE using constant
lDir.l = ExamineDirectory(#TEST_DIR_SEARCH, Directory$, "*.test")
If lDir
While NextDirectoryEntry(lDir)
If DirectoryEntryType(lDir) = #PB_DirectoryEntry_File
Type$ = "[File] "
Size$ = " (Size: " + DirectoryEntrySize(lDir) + ")"
Else
Type$ = "[Directory] "
Size$ = "" ; A directory doesn't have a size
EndIf
Debug Type$ + DirectoryEntryName(lDir) + Size$
Wend
FinishDirectory(lDir)
EndIf
CompilerEndIf
CompilerIf #TEST_CODE = 4
; declare a variable instead of hard coded
;Define iExDir.i = 0
iExDir.i = 0
; >>>> NOTE using Variable "iExDir"
lDir.l = ExamineDirectory(iExDir, Directory$, "*.test")
If lDir
While NextDirectoryEntry(lDir)
If DirectoryEntryType(lDir) = #PB_DirectoryEntry_File
Type$ = "[File] "
Size$ = " (Size: " + DirectoryEntrySize(lDir) + ")"
Else
Type$ = "[Directory] "
Size$ = "" ; A directory doesn't have a size
EndIf
Debug Type$ + DirectoryEntryName(lDir) + Size$
Wend
FinishDirectory(lDir)
EndIf
CompilerEndIf
Thanks
JAL