Call a B4P Sub function in C#...

sitajony

Active Member
Licensed User
Hi, today I aked me how call a sub function in C# writed on B4P?
I saw that we can use b4pobject() but I don't know how use it...
Anyone can help me for few seconds?
Thanks for your answers!
 

agraham

Expert
Licensed User
Longtime User
Several of my libraries can do this, in particular the Caller object in my http://www.b4x.com/forum/additional...-legacy-optimised-applications.html#post27120, but I'm not making the source for that available! It is not too difficult calling a Sub from a library in a compiled program - you need to know about delegates - but calling a Sub in the IDE needs a bit more knowledge about the internals of the IDE.

If you look in the cs file for my http://www.b4x.com/forum/additional-libraries/3045-scripting-library-b4ppc.html#post17029 the chsIDE (Call Host Sub IDE) method calls into the IDE. It restricts itself to calling Subs with string type parameters and a string returns but can be extended, as in my Debug library, to use any types accepted by Basic4ppc. The chs0 to chs3 methods call Subs when the library is compiled. This uses the same mechanism as the CallSub keyword and is therefore limited to Subs with up to three string parameters and a string return.
 

sitajony

Active Member
Licensed User
Thanks, you did a lot of great library but I need to implement it directly in my own source code... In fact I want run a sub function from Class1.c on Tzor folder... When an error is occured I want execute a sub function with in first paremettre the exception message...
Maybe there's a faster way for do it?
 

agraham

Expert
Licensed User
Longtime User
I need to implement it directly in my own source code...
I've told you where to find the code to do it! What more do you need?

In fact I want run a sub function from Class1.c on Tzor folder... When an error is occured I want execute a sub function with in first paremettre the exception message...Maybe there's a faster way for do it?
Sorry? :confused: No Comprende! Do you mean you want to access the Exception when an error occurs in Basic4ppc. Look at the cs file in my http://www.b4x.com/forum/additional-libraries/2305-exceptions-handling-library.html#post12486 and B4PObject(6).
 

sitajony

Active Member
Licensed User
Sorry I didn't explained very well:
I can't type ErrorLabel() on all my sub functions on B4P (I have an hundred). I would call a sub function from the ShowError() void function on the Class1.c available in the Tzor folder... It'll be faster than write a lot of ErrorLabel() on each sub function on my B4P source code... And in even time I get the error message... (optional, it's not serious if I can't get it directly from ShowError(), I can use your Lib Exeption...) I just want run a sub function without parametters if really I can't/it's too hard to write the c# code...

Tell me if you don't understand... I'm french and sometime I write too fast...
 

agraham

Expert
Licensed User
Longtime User
I can't believe that you have a hundred Subs that are likely to throw an Exception Surely there are only a few and only those few will need Errorlabel added.

Note that unlike C# Exceptions don't propagate up the call chain. An Exception is always handled in the Sub in which it occurred, either by a call to ShowError that requires user input, or by Errorlabel if it is present.

Whatever problem you think you have I don't think this is a good way to deal with it.
 

sitajony

Active Member
Licensed User
Not serious, I'll do differently...
Yes I've a hundred subs who need an errorLabel cause they are all dynamic, they need names and only the user can put the name and if it doesn't exist it return an error...
 
Top