Board index » cppbuilder » SaveDialog bug?

SaveDialog bug?


2005-02-21 05:52:11 PM
cppbuilder45
I've got this piece of code:
FILE *fi;
fi = fopen ("bla.txt", "r");
if (fi == 0)
Edit2->Text = "NULL";
else
Edit2->Text = "OK";
fclose (fi);
SaveDialog1->Execute(); // Line X
fi = fopen ("bla.txt", "r");
if (fi == 0)
Edit3->Text = "NULL";
else
Edit3->Text = "OK";
fclose (fi);
Edit1, Edit2, Edit3, SaveDialog1 are in a TForm.
The file bla.txt is present in the current dir.
The strange thing that happens is:
When the code above starts working it comes to Line X and the user is
prompted for action. If I choose "cancel" at the dialog, Edit1->Text and
Edit2->Text are "OK". But, if I type some filename and then select "save"
Edit2->Text is "OK" and Edit3->Text is "NULL;
If I select "save" again, both Edit1->Text and Edit2->Text are "NULL"; So,
why using SaveDialog1 interfers with fopen's work and prevents in from
opening files at sometimes and is it some kind of a bug or I'm not doing
something correctly. If a bug, how to solve the problem?
 
 

Re:SaveDialog bug?

"Analian" < XXXX@XXXXX.COM >wrote:
Quote

I've got this piece of code:
If you're using C++, why are you using old C-style file I/O?
Quote
SaveDialog1->Execute(); // Line X
You're defeating the purpose of the dialog. Execute is a bool
method and you should be checking if the user clicked 'open'
or if he/she canceled the operation:
if( SaveDialog1->Execute() )
{
ShowMessage( SaveDialog1->FileName );
}
~ JD
 

Re:SaveDialog bug?

Analian wrote:
Quote
I've got this piece of code:

FILE *fi;

fi = fopen ("bla.txt", "r");
if (fi == 0)
Edit2->Text = "NULL";
else
Edit2->Text = "OK";

fclose (fi);

SaveDialog1->Execute(); // Line X

fi = fopen ("bla.txt", "r");
if (fi == 0)
Edit3->Text = "NULL";
else
Edit3->Text = "OK";
fclose (fi);

Edit1, Edit2, Edit3, SaveDialog1 are in a TForm.
The file bla.txt is present in the current dir.

The strange thing that happens is:
When the code above starts working it comes to Line X and the user is
prompted for action. If I choose "cancel" at the dialog, Edit1->Text and
Edit2->Text are "OK". But, if I type some filename and then select "save"
Edit2->Text is "OK" and Edit3->Text is "NULL;
If I select "save" again, both Edit1->Text and Edit2->Text are "NULL"; So,
why using SaveDialog1 interfers with fopen's work and prevents in from
opening files at sometimes and is it some kind of a bug or I'm not doing
something correctly. If a bug, how to solve the problem?


Check If The Option On The SaveDialog OfNoChengeDir if true or false.
If The Option Is false The The dialog changes your working directory
into the one it displays. If The Option is true it does not change your
working directory.
apart from that your can declare a bool and you it like
bool result;
result=SaveDialog->Execute();
if (result){...}
else {....}
result is true when ok was pressed and false otherwise.
 

{smallsort}

Re:SaveDialog bug?

Quote
If you're using C++, why are you using old C-style file I/O?
I like C formatting more.
Quote
You're defeating the purpose of the dialog. Execute is a bool
method and you should be checking if the user clicked 'open'
or if he/she canceled the operation:
Yes, I use Execute(), just wondered what happened.
Quote
Check If The Option On The SaveDialog OfNoChengeDir if true or false.
Exactly what I needed. Thanks.
As speaking about options I've got this question:
If a filter *.bla is active, the OfOverwritePrompt option is set true, the
user has typed
"bla.bla" in the filename edit in the savedialog and a bla.bla file exist,
there is a prompt, ok. But
if the user has typed only "bla" without extension, the resulting filename
"bla.bla" corresponds to
an existing file but there is no prompt. Is there a way to avoid this
without manually checking it?