Hi everyone,
I'm working on a C# unit test where I use a dbSysDat instance derived from dbShellServer. When the underlying DBF file is missing, the VO.dbServer throws an error and displays a modal dialog.
From what I understand, this modal dialog is the default behavior and can be overridden by assigning a custom ErrorBlock. This seems to be straightforward in X#, but I'm unsure how to create and pass a CodeBlock from C# to the ErrorBlock function.
My goal is to handle the error in one of the following ways:
Log the error message to the test output
Throw it as a regular exception
Or suppress it entirely
Is it possible to achieve this from C#? If so, how would I go about creating a compatible CodeBlock or delegate?
Thanks in advance for your help!
Best regards,
JoeD
CodeBlock from C#
Re: CodeBlock from C#
Hi Joe,
I would create an X# DLL in VO dialect since you need the runtime and do all from there.
The X# DLL should expose only native .NET types to the C# application.
Wolfgang
I would create an X# DLL in VO dialect since you need the runtime and do all from there.
The X# DLL should expose only native .NET types to the C# application.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Re: CodeBlock from C#
Hi Wolfgang.
Thank you for your suggestion.
I'm not sure if it would be feasible for my approach to have a X#-DLL that exposes only native .NET types.
In the meantime I found the Macro Compiler and I use it like this to create the CodeBlock and redirect the ErrorHandler to my own Method.
Thank you for your suggestion.
I'm not sure if it would be feasible for my approach to have a X#-DLL that exposes only native .NET types.
In the meantime I found the Macro Compiler and I use it like this to create the CodeBlock and redirect the ErrorHandler to my own Method.
Code: Select all
public static void SetErrorHandler()
{
var macroCompiler = new MacroCompiler();
var codeBlock = macroCompiler.CompileCodeblock("{ |e| MyNamespace.MyClass.ErrorHandler(e)}");
XSharp.RT.Functions.ErrorBlock(codeBlock);
}
public static void ErrorHandler(__Usual x)
{
if (x.Value is Error e)
{
throw new Exception(e.Message, e);
}
throw new Exception("Unerwarteter Fehler: " + x.ToString());
}
Re: CodeBlock from C#
Hi Joe,
a C# application can work only with native .NET datatypes.
Variables with VO datatypes would be seen as instances of X# classes.
Wolfgang
a C# application can work only with native .NET datatypes.
Variables with VO datatypes would be seen as instances of X# classes.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it

