ReturnStrMethod

Applies to:Fast Math Parser
Class:uCalc.Callback
Sets the return value of a uCalc.Callback function as a String
Syntax
ReturnStr(Value)
Parameters
Value
String
String value that your callback returns
Returns
Nothing
Remarks
When you define a callback function with DefineFunction that returns a string, do it with ReturnStr.
Example 1: Returning a string (from a callback)

Sub TwiceStrCB(ByVal ExprPartPtr As IntPtr)
   Dim ExprPart As New uCalc.Callback(ExprPartPtr)
   ExprPart.ReturnStr(ExprPart.ArgStr(1) + ExprPart.ArgStr(1))
End Sub

Sub TwiceStr()
   uc.DefineFunction("Twice(Txt As String) As String", uc.PinAddr(AddressOf TwiceStrCB))
   Console.WriteLine(uc.EvalStr("Twice('Ha')")) ' Returns "HaHa"
End Sub

          

static void TwiceStrCB(IntPtr ExprPartPtr) {
   var ExprPart = New uCalc.Callback(ExprPartPtr);
   ExprPart.ReturnStr(ExprPart.ArgStr(1) + ExprPart.ArgStr(1));
}

static void TwiceStr() {
   uc.DefineFunction("Twice(Txt As String) As String", uc.PinAddr(TwiceStrCB));
   Console.WriteLine(uc.EvalStr("Twice('Ha')")); // Returns "HaHa";
}

          

procedure TwiceStrCB(ExprPartPtr: System.Pointer);
begin
   
//var ExprPart: uCalc.CreateCallback(ExprPartPtr);
   ExprPart.ReturnStr(ExprPart.ArgStr(1) + ExprPart.ArgStr(1));
End;

procedure TwiceStr();
begin
   
   uc.DefineFunction('Twice(Txt As String) As String', TwiceStrCB);
   WriteLn(uc.EvalStr('Twice("Ha")')); // Returns 'HaHa';
End;

          

void _stdcall TwiceStrCB(uCalcPtr ExprPartPtr) {
   auto ExprPart = uCalc::Callback(ExprPartPtr);
   ExprPart.ReturnStr(ExprPart.ArgStr(1) + ExprPart.ArgStr(1));
}

void TwiceStr() {
   uc.DefineFunction("Twice(Txt As String) As String", TwiceStrCB);
   cout << uc.EvalStr("Twice('Ha')") << endl; // Returns "HaHa";
}

          

static void TwiceStrCB(uCalcPtr ExprPartPtr) {
   auto ExprPart = uCalc::Callback(ExprPartPtr);
   ExprPart.ReturnStr(ExprPart.ArgStr(1) + ExprPart.ArgStr(1));
}

static void TwiceStr() {
   uc.DefineFunction("Twice(Txt As String) As String", ucPinAddr(TwiceStrCB));
   Console::WriteLine(uc.EvalStr("Twice('Ha')")); // Returns "HaHa";
}

          
DLL import code
<DllImport(uCalcDLL, CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.Cdecl, EntryPoint:="ReturnStr")> _

Private Sub ReturnStr__(ByVal ExprPartHandle As IntPtr,ByVal Value As String)
End Sub
            
[DllImport(uCalcDLL, CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl, EntryPoint="ReturnStr")]

protected static extern  void ReturnStr_(IntPtr ExprPartHandle, string Value);
            
{DLLImport}procedure ReturnStr__(ExprPartHandle: System.Pointer;Value: AnsiString); cdecl; external uCalcDLL name 'ReturnStr';

            
typedef  void (* __ReturnStr)(void *ExprPartHandle, CONSTCHAR Value ); 

            
[DllImport(uCalcLib, CharSet=CharSet::Ansi, CallingConvention=CallingConvention::Cdecl, EntryPoint = "ReturnStr")]

static void ReturnStr_(void *  ExprPartHandle, MARSHALSTR Value);
            
See also
Prev | Next