BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

File Open with Common Dialog Box Problem with Cancel

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Language C++)
View previous topic :: View next topic  
Author Message
Del Ventruella
Guest





PostPosted: Fri Jun 10, 2005 2:53 am    Post subject: File Open with Common Dialog Box Problem with Cancel Reply with quote




When I open a file using the Common Dialog Box, if I select the cancel option, my code still tries to open the file. The code begins with:

OpenDialog1->Execute();

The remaining lines translate the contents of a file into user readable information on a form. No problems with that, but it is clear that selecting CANCEL in the file open dialog box doesn't stop the execution of subsequent code after the line shown. My problem is how to recognize the "CANCEL" selection after "OpenDialog1->Execute();" if a file is not selected.

I don't want to try to read data that hasn't been loaded if no file is selected to be opened and "CANCEL" is instead selected. I recall seeing something like "OnCancelExecute()" in other code but don't know how to come up with the precise way to code this.

Thanks for your help with this in advance.

Back to top
Jonathan Benedicto
Guest





PostPosted: Fri Jun 10, 2005 3:01 am    Post subject: Re: File Open with Common Dialog Box Problem with Cancel Reply with quote



"Del Ventruella" <ventruella (AT) hotmail (DOT) com> wrote

Quote:
When I open a file using the Common Dialog Box, if I select the
cancel option, my code still tries to open the file. The code
begins with:

OpenDialog1->Execute();

The remaining lines translate the contents of a file into user
readable information on a form. No problems with that, but it is
clear that selecting CANCEL in the file open dialog box doesn't stop
the execution of subsequent code after the line shown. My problem
is how to recognize the "CANCEL" selection after
"OpenDialog1->Execute();" if a file is not selected.

I don't want to try to read data that hasn't been loaded if no file
is selected to be opened and "CANCEL" is instead selected. I recall
seeing something like "OnCancelExecute()" in other code but don't
know how to come up with the precise way to code this.

Thanks for your help with this in advance.

OpenDialog1->Execute() returns a boolean value indicating whether the
user clicked OK or Cancel.

So use something like this:

if( OpenDialog1->Execute() )
{
// OK was clicked.
}

HTH

Jonathan



Back to top
Del Ventruella
Guest





PostPosted: Fri Jun 10, 2005 4:08 pm    Post subject: Re: File Open with Common Dialog Box Problem with Cancel Reply with quote




"Del Ventruella" <ventruella (AT) hotmail (DOT) com> wrote:
Quote:

When I open a file using the Common Dialog Box, if I select the cancel option, my code still tries to open the file. The code begins with:

OpenDialog1->Execute();

The remaining lines translate the contents of a file into user readable information on a form. No problems with that, but it is clear that selecting CANCEL in the file open dialog box doesn't stop the execution of subsequent code after the line shown. My problem is how to recognize the "CANCEL" selection after "OpenDialog1->Execute();" if a file is not selected.

I don't want to try to read data that hasn't been loaded if no file is selected to be opened and "CANCEL" is instead selected. I recall seeing something like "OnCancelExecute()" in other code but don't know how to come up with the precise way to code this.

Thanks for your help with this in advance.



I tried to embed the file open code inside the brackets of the conditional statement previously suggested. In response, clicking on "CANCEL" once within the open dialog causes the open dialog to be displayed again. Clicking "CANCEL" twice causes the open dialog to close. Does anyone know the reason for this behavior? No command to open the open dialog box is contained within the code inside the brackets.

Thanks once again.

Back to top
Jonathan Benedicto
Guest





PostPosted: Fri Jun 10, 2005 4:11 pm    Post subject: Re: File Open with Common Dialog Box Problem with Cancel Reply with quote

"Del Ventruella" <ventruella (AT) hotmail (DOT) com> wrote

Quote:
I tried to embed the file open code inside the brackets of the
conditional statement previously suggested. In response, clicking
on "CANCEL" once within the open dialog causes the open dialog to be
displayed again. Clicking "CANCEL" twice causes the open dialog to
close. Does anyone know the reason for this behavior? No command
to open the open dialog box is contained within the code inside the
brackets.

Does your code look like this:

OpenDialog1->Execute();

if( OpenDialog1->Execute() )
{
...
}

If it does, you need to remove the first call to Execute. You don't
want to execute the dialog twice.

HTH

Jonathan



Back to top
Del Ventruella
Guest





PostPosted: Fri Jun 10, 2005 8:56 pm    Post subject: Re: File Open with Common Dialog Box Problem with Cancel Reply with quote


"Jonathan Benedicto" <incorrect (AT) no (DOT) server> wrote:
Quote:
"Del Ventruella" <ventruella (AT) hotmail (DOT) com> wrote in message
news:42a9bae2$1 (AT) newsgroups (DOT) borland.com...
I tried to embed the file open code inside the brackets of the
conditional statement previously suggested. In response, clicking
on "CANCEL" once within the open dialog causes the open dialog to be
displayed again. Clicking "CANCEL" twice causes the open dialog to
close. Does anyone know the reason for this behavior? No command
to open the open dialog box is contained within the code inside the
brackets.

Does your code look like this:

OpenDialog1->Execute();

if( OpenDialog1->Execute() )
{
...
}

If it does, you need to remove the first call to Execute. You don't
want to execute the dialog twice.

HTH

Jonathan



No, that's not the problem. I got it to work by finding the code you embedded inside the conditional statement's brackets in your last response within Borland's help files, and using it merely to get the file name.

I then test to see if the variable to which the file name is assigned is a null character. If not, my code uses the file name received to open the file. If no name is returned, it does nothing. Now it works to open a file, and there is no ambiguity if "cancel" is selected.

Thanks for trying to help out. It got me thinking and moving toward a solution again, which represented a form of help in itself.

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Language C++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.