Page 1 of 1
Close All Creating a Runtime Error
Posted: Tue Aug 18, 2020 4:46 pm
by Jeff Stone
Now that I have X# installed in VS2019, I am doing some simple testing. When trying to run the following code, I am getting some kind of runtime error that is flashing too quickly on the screen for me to read:
Code: Select all
FUNCTION Start( ) AS VOID
FoxProMessage = "Hello VFP!"
? FoxProMessage
use f:xsharpdeallist
? dealname
skip
? dealname
wait
Close All
wait
RETURN
If I replace Close All with Use, the program runs cleanly.
Regards,
Jeff
Close All Creating a Runtime Error
Posted: Tue Aug 18, 2020 5:59 pm
by Chris
Hi Jeff,
That's because the CLOSE ALL command has not been defined, so the compiler thinks you need to close a database named "ALL" and thus it fails
Thanks for your report, we will enable CLOSE ALL to work properly in the next build. In the meantime, you can use instead
CLOSE DATABASES
and it will work as expected. You can also put this in the beginning of your .prg file
#command CLOSE ALL => DbCloseAll()
and his way you can also use CLOSE ALL now.
Close All Creating a Runtime Error
Posted: Tue Aug 18, 2020 7:03 pm
by Jeff Stone
Hi Chris,
This CLOSE ALL issue isn't a big deal. I just figured that I would mention it to you. Is there a more preferred method/forum to report issues? And is there an updated Foxpro Command/Function List that I should look at first before reporting an issue?
More problematic may be that the command window that pops up flashes the runtime error message and then closes. Is it possible to keep the command window open so that a user can actually read the error message?
Regards,
Jeff
Close All Creating a Runtime Error
Posted: Tue Aug 18, 2020 7:20 pm
by robert
Jeff,
The recommended way to catch errors is to have a TRY .. CATCH .. END TRY in your start function. Something like this:
FUNCTION Start() as VOID
TRY
.
.statements
.
CATCH e AS Exception
? e:ToString()
END TRY
WAIT
RETURN
Close All Creating a Runtime Error
Posted: Tue Aug 18, 2020 9:17 pm
by Jeff Stone
Thanks, Robert. The VFP interpreter spoils us with regards to trapping errors. I added the TRAP code and got the following message:
Hello VFP!
SB102
HYB21
Description : Invalid alias specification
Subsystem : DBCMD
GenCode : EG_ARG Argument error
SubCode : 1010 Invalid alias specification
FuncSym : ERROR:VODBERROR
Severity : ES_ERROR
Can Default : False
Can Retry : False
Can Substitute : False
Argument : All
Arguments : {All}
Stack Trace :
at XSharp.RT.Functions.__pushWorkarea(__Usual alias)
at XSharpFoxPro1.Exe.Functions.Start() in f:xsharptestappPrgStart.prg:line 9
Press any key to continue...
The CLOSE ALL statement was actually on line 10 rather than line 9. I don't know if the error reporting is always 1 line lower than it should be or if it is just in this instance.
FWIW, for compiled versions of VFP many of us use the ON ERROR command:
Code: Select all
ON ERROR DO errHandler WITH ;
ERROR( ), MESSAGE( ), MESSAGE(1), PROGRAM( ), LINENO( )
USE nodatabase
ON ERROR && Restores system error handler.
PROCEDURE errHandler
PARAMETER merror, mess, mess1, mprog, mlineno
CLEAR
? 'Error number: ' + LTRIM(STR(merror))
? 'Error message: ' + mess
? 'Line of code with error: ' + mess1
? 'Line number of error: ' + LTRIM(STR(mlineno))
? 'Program with error: ' + mprog
ENDPROC
Close All Creating a Runtime Error
Posted: Wed Aug 19, 2020 7:47 am
by robert
Jeff,
The line number 10 instead of 9 was actually a compiler error. The code get translated to
- push current area and select new workarea All
- close workarea
- pop current workarea
All three instructions should be bound to line number 10 but the first instruction did not have this binding, so the line number was still the line number of the previous line of code.
Robert