Function with ignored parameter

Hello,

I use the function “RemoveEntireFolder” from the Xojo documentation (in “FolderItem”)

Function RemoveEntireFolder(theFolder As FolderItem, continueIfErrors As Boolean = False) As Integer

I want to use a third parameter (delFolders As Boolean) to define if the folders once emptied are deleted:

(theFolder As FolderItem, delFolders As Boolean = False, continueIfErrors As Boolean = False)

I call the function with False param:

Var f As New FolderItem
f = SpecialFolder.UserHome.Child("Downloads") 
Call RemoveEntireFolder(f,false,true) 

But, the result is always True and the folders always deleted!
What do you think is the problem?

If returnCode = 0 Then
    Try
    **if delFolders then**
           theFolder.Remove 
    **end**
  Catch error As IOException
    returnCode = error.ErrorNumber
  End Try
End If

Thanks

RemoveEntireFolder seems to be a Method, returns nothing, so you can remove Call.

Maybe a reboot can help ?

Else clears the Xojo cache folder contents…

Nota: I have 813 elements in my Downloads folder… for >224GB…

Something else must be going on here. Do you have other calls to this function that you haven’t updated for the new parameter?

Set a breakpoint on the first line of the function and check the Stack pane of the debugger to make sure that you’re seeing what you think you’re seeing.


In that screenshot, you can see that my call to the function originated from Window1.Opening. If I click on Window1.Event.Opening, I can see the function call itself and verify the parameter values that I’m passing.

Thanks.
There are no other calls to this function.

Thanks.
“Maybe a reboot can help ?” Always not !

1 Like

That parameter value has to be coming from somewhere. Did you follow my instructions above and inspect what’s happening to result in delFolders being True? Set a breakpoint on your call to RemoveEntireFolder and look at the values in the debugger.

dont you just need:

Call RemoveEntireFolder(f,true,true) // remove entire folder and contiue if errors true both
If this is the function signature:
Function RemoveEntireFolder (theFolder As FolderItem, delFolders As Boolean = False, continueIfErrors As Boolean = False) As Integer

I don’t really understand what you mean…

Some parameters are optional. You can use

RemoveEntireFolder (theFolder As FolderItem)

The method is expecting the second parameter to be continueIfErrors. Now you made delFolders the second parameter! When adding new parameters it’s a better idea to append them to the end of the parameter list to avoid problems like this, especially when recursion is involved. The method may not be called from anywhere else in your program, but it calls itself!

4 Likes

It returns an integer

What it has to do whith the post? And what is NOTA???

1 Like

If you want a real answer instead of all kind of guesses, you should put the complete code of the function. Maybe you change the value of delFolders somewhere else.

If not, Try to put a break BEFORE the call to the function and see if you are sending the True value, Put another break inside the function right at the top and check what are you getting.

I understood the problem, the last two parameters are reversed! It works by reversing the last two parameters! but I don’t understand why.
Maybe because I added an additional parameter in second position, it is always considered as the last arrived!
Here is how they are declared:
RemoveEntireFolder

As I said in my response, it’s because the method is recursive. When it calls itself, it’s expecting continueIfErrors in the second parameter, not the third.

3 Likes

I understand better, thank you.

1 Like

He delete the Download contents…
Nota Bene.

This demonstrates the dangers of optional parameters, especially use of more than one. Had the parameters not been optional, I think the compiler would have caught the issue.