Dialog.OpenFile()

Post your Gambas programming questions here.
User avatar
grayghost4
Posts: 174
Joined: Wednesday 5th December 2018 5:00am
Location: Marengo, Illinois usa

Dialog.OpenFile()

Post by grayghost4 »

This is kinda a discussion topic :D

Can anyone explain the logic of pressing CANCEL should return TRUE ?
Seems to me that an affirmative response should return true.
If Dialog.OpenFile() Then
  Return ' User pressed Cancel -
Endif
User avatar
PJBlack
Posts: 184
Joined: Tuesday 9th June 2020 10:26pm
Location: Florstadt, Hessen, Germany

Re: Dialog.OpenFile()

Post by PJBlack »

maybe this comes from the underlying gui kit ...
maybe its less typing to use If instead of If Not or IF Else ...
User avatar
BruceSteers
Posts: 1521
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Dialog.OpenFile()

Post by BruceSteers »

It's based on the return is an error value I think.

So if true an error has occurred.
If at first you don't succeed , try doing something differently.
BruceS
User avatar
stevedee
Posts: 518
Joined: Monday 20th March 2017 6:06pm

Re: Dialog.OpenFile()

Post by stevedee »

BruceSteers wrote: Thursday 31st December 2020 10:02pm It's based on the return is an error value I think.

So if true an error has occurred.
I think I see where you are coming from Bruce, but I don't think True indicates an error in this case.

I tried some test code yesterday. Here is my code showing breakpoints and object viewers, in case anyone is interested.
DialogLogic.png
DialogLogic.png (124.96 KiB) Viewed 20869 times
Clearly Dialog.OpenFile() needs to return an indication for the programmer that either the open or cancel button was pressed.
Also note that there is no attempt (internally in the Dialog class) to clear the Dialog.Path or Dialog.Paths array when cancel is pressed.
There is no class property to indicate that Open or Save dialog has been requested, and no Events are raised.
There is no attempt to return error codes via the Return value (as might be the case if the return type was an integer).
The return type is a Boolean which indicates either Open or Cancel (or Save/cancel in the case of the Save method).

So my conclusion is that the logic appears to be reversed from what I would expect. {although I suspect the author had his reasons}


BTW;
I tested using gb.Form.Dialog (the enhanced dialog).

But when I tried to run my code with the standard dialog I started getting this strange error.
IntCrash.png
IntCrash.png (40.29 KiB) Viewed 20869 times
There's probably something nasty in my code, but I can't immediately see what it is.
User avatar
BruceSteers
Posts: 1521
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Dialog.OpenFile()

Post by BruceSteers »

Yeah I guess the mailing list is the place to get real answer for this. Ben would know for sure
If at first you don't succeed , try doing something differently.
BruceS
User avatar
grayghost4
Posts: 174
Joined: Wednesday 5th December 2018 5:00am
Location: Marengo, Illinois usa

Re: Dialog.OpenFile()

Post by grayghost4 »

Since I am kinda new at Gambas I was just wondering if I was misunderstanding some thing or using it incorrectly.
Simple enough to use the one-liner ;)
If Dialog.OpenFile() Then Return  ' "True" =  User canceled 
' use the file  
Thank for the feedback

Marv
cage
Posts: 123
Joined: Monday 2nd September 2019 5:47am
Location: Phoenix Arizona

Re: Dialog.OpenFile()

Post by cage »

This is what I use in a program where I select program names. If I click on cancel it closes the dialog and returns to the under lying window. Hope it helps.
Public Sub FileChooser1_Activate()
   ' Sends selected name to global variable
   Global.CopyCmd = FileChooser1.Value
   
   Me.Close
   
End

Public Sub FileChooser1_Cancel()

   Me.Close

End
User avatar
grayghost4
Posts: 174
Joined: Wednesday 5th December 2018 5:00am
Location: Marengo, Illinois usa

Re: Dialog.OpenFile()

Post by grayghost4 »

I may be missing something ... why would you go through all that trouble and extra code ..
when a one-liner does it all ?
User avatar
stevedee
Posts: 518
Joined: Monday 20th March 2017 6:06pm

Re: Dialog.OpenFile()

Post by stevedee »

grayghost4 wrote: Sunday 3rd January 2021 8:40am I may be missing something ...
That's a good question.

Take a look at all the Methods, Properties & Events available with the FileChooser compared to a relatively simple dialog box,
FileChooser.png
FileChooser.png (181.25 KiB) Viewed 20771 times
If you don't need any of these, then use a Dialog. But maybe your app needs Bookmarks or you need some of the Events on offer.

There are quite a few directory/file related controls available in Gambas...possibly too many.
cage
Posts: 123
Joined: Monday 2nd September 2019 5:47am
Location: Phoenix Arizona

Re: Dialog.OpenFile()

Post by cage »

While the Dialog Openfile works quite well, I have not found that the Dialog Path can be set even though the documentation says it can. That is why I use FileChooser instead. It allows me many more options then with the OpenFile dialog. Otherwise the OpenFile Dialog works extremely well, just not for my application where setting path is really necessary. Depending on your needs either one will do a great job.
Post Reply