Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Calling a C++ Builder function and passing parameters from a Javascript function
#2
(03-27-2019, 07:29 PM)amine1980 Wrote: I need to call a c++ builder function from a HTML button. 

That requires either:
  • a web browser to be embedded in your C++ app, and that the app either:
    • uses the browser's DOM to hook the HTML button itself and assign a handler to its onClick event.
    • registers a COM object with the browser such that scripts within the HTML can access the object via `window.external` (which is deprecated in modern browsers).
  • you to create an COM object that the Javascript can instantiate when needed (typically only works in IE browsers).

(03-27-2019, 07:29 PM)amine1980 Wrote: I know that i can call some functions using the button events (async or not) but i need to call a function with parameters like that:

Javascript Code:

Code:
function add(a,b)
{
       var result = a + b;
       DisplayNumber(result);
}

C++ Builder Code:

Code:
void __fastcall TForm1::DisplayNumber(int number)
{
       ShowMessage(number);
}

Is this possible?

Not exactly the way you have presented it, but yes, in general it is possible to do something like that, with some extra work on the app's part to setup a bridge between the Javascript and C++ codes. But HOW you do it depends on WHICH BROWSER you are using.

But, since you are posting this in an IntraWeb forum, and IntraWeb is server-side, then no, you cannot directly call a server-side C++ function in client-side Javascript. The Javascript would have to invoke its own code to connect to the server and send a request, such as with AJAX, and then the server-side code will have to respond to that request by executing the desired C++ function.

Reply


Messages In This Thread
RE: Calling a C++ Builder function and passing parameters from a Javascript function - by rlebeau - 03-27-2019, 11:49 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)