RTC Forums
November 01, 2024, 12:53:15 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: Using rtc_function as RTCFunction parameter  (Read 5938 times)
Theprasit
RTC License++
*****
Posts: 42


« on: May 31, 2013, 04:56:23 AM »

In the document said that we can call RTCFunction by using RTCFunction as parameter.

Do you have any example code on using this?

Thank you and Regards,
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #1 on: May 31, 2013, 12:48:43 PM »

RTC remote functions are explained here.

For examples on nested remote function calls, see this FAQ topic.

Best Regards,
Danijel Tkalcec
Logged
Theprasit
RTC License++
*****
Posts: 42


« Reply #2 on: June 02, 2013, 11:44:27 AM »

Just went thru FAQ for "Add" with nested 2 "mull" function call.
What about remote function on the server side?

You said that "Remote functions on the server-side do not have to be specially prepared to be able to execute nested function calls,"
Seem to me that we have to prepare remote function "ADD" with nested "Mull" inside.

Could you give me an example of remote function on the server side for my clearer picture?

Thank you and Regards,
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #3 on: June 02, 2013, 12:24:06 PM »

You don't have to make any special precautions in the OnExecute event of a TRtcFunction component to accept a Result from another remote function. You just have to make sure that the Result of a nested remote function returns the data in the type you are expecting.

Let's take "Add" and "Mull" functions as examples and implement their TRtcFunction.OnExecute events like this:

// OnExecute event of the "Add" remote function ( Result := A + B ):
begin
  Result.asFloat := Param.asFloat['A'] + Param.asFloat['B'];
end;

// OnExecute event of the "Mull" remote function ( Result := A * B ):
begin
  Result.asFloat := Param.asFloat['A'] * Param.asFloat['B'];
end;

Let's say we want the Server to execute this code and return the result:
Result := Mull ( Add( Mull(12.1, 13.2) , Mull(14.3, 15.4) ), 16.5 )

To prepare the above nested "Add" and "Mull" calls, execute them on the Server and return the result to our Client, we can do it like this (on the Client side):

with rtcClientModule do
  begin
  with Data.newFunction(’mull’) do
    begin
    with newFunction(’A', ‘add’) do
      begin
      with newFunction('A', 'mull') do
        begin
        asFloat[’A']:=12.1;
        asFloat[’B']:=13.2;
        end;
      with newFunction('B', 'mull') do
        begin
        asFloat['A']:=14.3;
        asFloat['B']:=15.4;
        end;
      end;
    asFloat['B']:=16.5;
    end;
  Result := Execute.asFloat;
  end;

Best Regards,
Danijel Tkalcec
Logged
Theprasit
RTC License++
*****
Posts: 42


« Reply #4 on: June 03, 2013, 03:27:22 AM »

Thank you for your quick response. Your code sample is much more clear for me even not close to my expectation.

Since start using RTC, I seem that we have to have several remote functions to serve our tasks. More better if we can reduce those by using parameter passing, that which I expected. Anyway, nested function call have some more benefit, I will try Script engine to create flexible remote command instead.

What about "Anonymous Method" support for RTC?  Wink

Best Regards 
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #5 on: June 03, 2013, 12:08:38 PM »

What you do in your code on the Server and the Client side is entirely up to you. The RTC SDK is there to assist you in your communication tasks, but you should NOT look at remote functions as a direct replacement for local functions. Remote Functions a simple a way to send data from the Client to the Server, process that data on the Server, and return a response back to the Client.

Best Regards,
Danijel Tkalcec
Logged
Theprasit
RTC License++
*****
Posts: 42


« Reply #6 on: June 03, 2013, 04:59:00 PM »

I understood about the concept you mentioned, as I told before, if we need several server function, we have to create a lot of remote function on the server side, lead in more maintenance code. If we can use such kind of Script Engine, should be better and reduce number of maintenance code.

Seem that I have a long journey with RTC, several area to try and find out.

Thank you for your valuable product.

Cheer!
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.024 seconds with 16 queries.