Scripter->OnCompileError and ->OnRuntimeError

I think I need to use these properties to catch errors and exit the script engine smoothly.

I use C++ builder. XE6.

I think from reading the documents and forums that I need to register TatEventDispatcher and use the DefineEventAdapter. But since I'm using C++ builder most of the help I've read is about Delphi/Pascal so I was having trouble getting it registered.

I thought it might be similar to this?:

TatClass *TEventDispatcherClass = Scripter->DefineClass(__classid(TatEventDispatcher));
DefineEventAdapter(TScriptErrorEvent, TEventDispatcherClass, MethodAddress, false);

I also was not sure of the MethodAddress. Should I define a method of the EventDispatcherClass for OnCompileError and put it here?

Thanks for the help.

But you want the script itself,  to respond to a OnCompileError/OnRuntimeError itself? It doesn't make much sense to me, especially the OnCompileError?

And not only that, you want to set the event handler from the script? That's the only reason why you would want to add an event adapter for it. What exactly do you want to achieve?

My goal is to exit the scripter engine without hanging the rest of my program.

As it is right now, I am using the scripter programmatically. So the user isn't using the IDE or anything in this case. The user has a set of data that he wants the script engine to manipulate and then put back so that the rest of my program can run with this newly updated data.

What happens now, the user runs my program, it grabs a set of data, the script changes the data and puts the data back, and my program runs with the new data.

The problem I face is if the script itself contains an error. In this case what I see is this:

The user runs my program, it grabs a set of data, the script engine initializes and executes, and then everything just sits and hangs there. The user has to force close the whole program.

So, I thought that if I was able to overwrite and control these OnCompileError and OnRuntimeError events, I would be able to catch these errors when the script engine hits them, and then exit the engine correctly.

Judging by your response, I am really missing something. What would be the correct way to catch these errors and exit the engine?

The problem is in the fact that scripting is hanging. It shouldn't. If there is a compile or runtime error,  scripter will just raise an exception and leave. It goes to the normal Delphi exception-handling system. Is the scripter being executed in a thread, a dll, or something non-visual? If it's the main thread and regular VCL application, you should just see the error message of the exception.

Reviewing this again, yes the scripter is not visible, so when the error messages should have shown, they were not. The reason my program was hanging was not because I was waiting on the scripts error message like I had thought.