Klaus said:
When does it happen, that you look for an error in any button?
The tools for fixing errors are error handling and the debugger. And they will tell you exactly which button (or other object) has an error, I don't see the grouping of objects as helpful for that specific purpose. It's helpful in a more general way, but also only, if you need to modify all same object types, and that's better solved using classes, actually.
One very handy way of error handling is to put a programmatic breakpoint into your error handler, so you can step to the line of error in debugging.
Run this:
Code:
On Error myerrhandler()
Set TablePrompt Off
Use nonexistingtable
Use
Procedure myerrhandler()
Local Array laError[1],laStack[1]
=Aerror(laError)
=Astackinfo(laStack)
* inspect those arrays in the locals window of the debugger
If _vfp.StartMode = 0 && running within the IDE
Set Step On
Retry
Endif
Using Retry will bring you back to the line that errored, when you testrun code within the IDE. If that happens in an EXE what's missing is storing the error information in an error log table or text. This is not to demonstrate good error handling, just the aspect of enabling to live debug an error by using RETRY.
I think you indicate the case when you found an error and know all your buttons will have the same error, as you copy pasted code, so that RETRY only brings you into one button nd not all of them (and there is no editing of code during debugging, anyway).
Well, but that's the general error of not using a button class instead of repeating code. And if the code would be so individual you can't put it into a single class, use two or more. On the other side, if you have repeated errors it points out that code is shared among multiple buttons.
The size of a project doesn't make classes over the top. It's always good to centralize the same code into a class, so errors are not copied all over the place, but also stay localized in one point to fix.
PS: One more thing about why to use SET STEP ON and not SUSPEND and why to use RETRY:
1. SET STEP ON brings up the debugger and suspends code execution, it's a programmatic break point. I know Tamar always points out use SUSPEND instead. Well, here I'd highly recommend SET STEP ON, because it will bring up the debugger, no matter if it already is open or not
2. RETRY brings you back to the line that errored, and at first blush that sound unpractical, as the line will error again.
Yes, it most often will, the reason to use RETRY is not to actually retry but to get you to the point of error, no matter if it's in the middle of code or the last line of the method/event/procedure/function failing. If you'd RETURN, you'd return to the line after the error, and when the error is in the last line of code of something, you don't get to the place of the error, but could end up at READ EVENTS, in the worst case, if the error happens in the last line of a button click that was happening by a actual click, because after that VFP would return to the READ EVENTS line. Aside from ASTACKINFO and AERROR info you'd have no clue where the error happened, therefore both SET STEP ON and RETRY for live debugging.
PPS: What to do, when you're at the line of error in the debugger?
Well, you often easily spot the error in code and you can make use of a nice feature of debugging: The command window can execute within the context of the current procedure/function/method/event, which in case of objects does not only mean you can access local variables, as if the command window is within the currently executing code section, you can also use THIS, which normally errors when used in the command window. So you could write the line that errored without an error, execute, then set the program pointer to the next line and continue, confirming your fix works. Now stop the debug session, copy the lat line of the command window into the error line and you fixed it. So the command window is also your clipboard for memorizing the fix temporarily. I'd still rather like to be able to edit the actually running object, whether it's a class, form, PRG, whatever. That's still impossible, but at least you have the command window as placeholder.
Chriss