| View previous topic :: View next topic |
| Author |
Message |
Tom Woodrow Guest
|
Posted: Sat Aug 06, 2005 6:00 am Post subject: How to verify a file is not opened in EXCEL |
|
|
Hope that this is the correct group.
I load CSV files into TStringGrid (or TAdvStringGrid). This works great
unless the CSV file is already opened in EXCEL. If this happens I get
error that I can't seem to trap with try/catch.
What is the best way to verify that a CSV file is NOT already opened in
EXCEL before attempting to open with string grid?
Thanks
Tom Woodrow
|
|
| Back to top |
|
 |
Vladimir Stefanovic Guest
|
Posted: Sat Aug 06, 2005 6:57 am Post subject: Re: How to verify a file is not opened in EXCEL |
|
|
I'm not sure how to check if it's opened by EXCEL
but I know how to check if it is opened by some
other program.
Look at:
http://tinyurl.com/75nlq
There is a routine IsFileOccupied(). Also this routine
must be executed after checking if file exists, etc...
--
Best regards,
Vladimir Stefanovic
"Tom Woodrow" <tomwoodrow (AT) comcast (DOT) net> wrote
| Quote: | Hope that this is the correct group.
I load CSV files into TStringGrid (or TAdvStringGrid). This works great
unless the CSV file is already opened in EXCEL. If this happens I get
error that I can't seem to trap with try/catch.
What is the best way to verify that a CSV file is NOT already opened in
EXCEL before attempting to open with string grid?
Thanks
Tom Woodrow
|
|
|
| Back to top |
|
 |
Tom Woodrow Guest
|
Posted: Sat Aug 06, 2005 5:27 pm Post subject: Re: How to verify a file is not opened in EXCEL |
|
|
Vladimir,
Thanks for the suggestions. First I use FileExists to verify the file
than use the IfFileOccupied routine from the URL you sent me. I opened a
file with EXCEL and then tested it with IsFileOccupied (below) and get
the EFOpenError exception. It works ok and returns false if the file is
not opened. For some rason the try/catch mechanism is not working here.
Any suggestions?
Thanks
Tom Woodrow
bool IsFileOccupied( const char* s )
{
try
{
TFileStream *tStream = new TFileStream( AnsiString( s ),
fmOpenRead|fmShareExclusive );
delete tStream;
return( false );
}
catch ( const Exception& )
{
return( true );
}
}
Vladimir Stefanovic wrote:
| Quote: | I'm not sure how to check if it's opened by EXCEL
but I know how to check if it is opened by some
other program.
Look at:
http://tinyurl.com/75nlq
There is a routine IsFileOccupied(). Also this routine
must be executed after checking if file exists, etc...
|
|
|
| Back to top |
|
 |
Vladimir Stefanovic Guest
|
Posted: Sat Aug 06, 2005 5:53 pm Post subject: Re: How to verify a file is not opened in EXCEL |
|
|
| Quote: | [...] I opened a file with EXCEL and then tested it with
IsFileOccupied (below) and get the EFOpenError
exception. It works ok and returns false if the file is not opened. For
some rason the try/catch mechanism is
not working here.
|
It works fine for me. One reason why you can get the
exception is when you start the program from IDE!
Try to execute you program from explorer.
--
Best regards,
Vladimir Stefanovic
|
|
| Back to top |
|
 |
Tom Woodrow Guest
|
Posted: Sat Aug 06, 2005 6:15 pm Post subject: Re: How to verify a file is not opened in EXCEL |
|
|
Vladimir,
OK, from the IDE it works properly. Is there any way to get it to work
within the IDE also.
Thanks
Tom Woodrow
Vladimir Stefanovic wrote:
| Quote: | [...] I opened a file with EXCEL and then tested it with
IsFileOccupied (below) and get the EFOpenError
exception. It works ok and returns false if the file is not opened. For
some rason the try/catch mechanism is
not working here.
It works fine for me. One reason why you can get the
exception is when you start the program from IDE!
Try to execute you program from explorer.
|
|
|
| Back to top |
|
 |
Heinrich Wolf Guest
|
Posted: Sat Aug 06, 2005 6:41 pm Post subject: Re: How to verify a file is not opened in EXCEL |
|
|
"Tom Woodrow" <tomwoodrow (AT) comcast (DOT) net> schrieb im Newsbeitrag
news:42f4fe39$1 (AT) newsgroups (DOT) borland.com...
| Quote: | Vladimir,
OK, from the IDE it works properly. Is there any way to get it to work
within the IDE also.
Thanks
Tom Woodrow
|
Hi
modify the exception handling of the IDE.
Menu: Tools - Debugger-Options
There are 2 Tabs with many settings.
Regards
Heiner
|
|
| Back to top |
|
 |
Vladimir Stefanovic Guest
|
Posted: Sat Aug 06, 2005 6:46 pm Post subject: Re: How to verify a file is not opened in EXCEL |
|
|
| Quote: | OK, from the IDE it works properly. Is there any way
to get it to work within the IDE also.
|
Yes, there is a way, but I'm not sure about the steps.
Probably:
Tools / Debugger Options / [maybe] OS Excptions
.... and try checking/unchecking to find out how to supress
exceptions.
--
Best regards,
Vladimir Stefanovic
|
|
| Back to top |
|
 |
|