Close All Creating a Runtime Error

This forum is meant for questions about the Visual FoxPro Language support in X#.

Post Reply
Jeff Stone
Posts: 34
Joined: Fri Jun 07, 2019 4:16 pm

Close All Creating a Runtime Error

Post 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
User avatar
Chris
Posts: 4562
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Close All Creating a Runtime Error

Post 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.
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
Jeff Stone
Posts: 34
Joined: Fri Jun 07, 2019 4:16 pm

Close All Creating a Runtime Error

Post 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
User avatar
robert
Posts: 4225
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Close All Creating a Runtime Error

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
Jeff Stone
Posts: 34
Joined: Fri Jun 07, 2019 4:16 pm

Close All Creating a Runtime Error

Post 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
User avatar
robert
Posts: 4225
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Close All Creating a Runtime Error

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
Post Reply