RTC Forums

Subscription => Support => Topic started by: Theprasit on May 31, 2013, 04:56:23 AM



Title: Using rtc_function as RTCFunction parameter
Post by: Theprasit 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,


Title: Re: Using rtc_function as RTCFunction parameter
Post by: D.Tkalcec (RTC) on May 31, 2013, 12:48:43 PM
RTC remote functions are explained here. (https://rtcforum.teppi.net/index.php?topic=311.0)

For examples on nested remote function calls, see this FAQ topic (http://realthinclient.com/sdkarchive/index2ccb2ccb.html).

Best Regards,
Danijel Tkalcec


Title: Re: Using rtc_function as RTCFunction parameter
Post by: Theprasit 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,


Title: Re: Using rtc_function as RTCFunction parameter
Post by: D.Tkalcec (RTC) 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


Title: Re: Using rtc_function as RTCFunction parameter
Post by: Theprasit 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?  ;)

Best Regards 


Title: Re: Using rtc_function as RTCFunction parameter
Post by: D.Tkalcec (RTC) 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


Title: Re: Using rtc_function as RTCFunction parameter
Post by: Theprasit 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!