RTC Forums

Subscription => Support => Topic started by: xdu2050 on April 21, 2017, 10:21:02 AM



Title: How to add many of RtcFunctions to RtcFuntionGroup
Post by: xdu2050 on April 21, 2017, 10:21:02 AM
I want to  add many of  TRtcFunction to TRtcFunctionGroup, or TRtcFunctionGroup load a script file, compile as a global method.

Can add this procedure?


Title: Re: How to add many of RtcFunctions to RtcFuntionGroup
Post by: D.Tkalcec (RTC) on April 21, 2017, 10:32:00 AM
You can add as many "TRtcFunction" components to a single "TRtcFunctionGroup" component as you want. Simply assign the "TRtcFunctionGroup" instance to the "Group" property of each "TRtcFunction" component. You can do this in code (it is a simple assignment) or in the Delphi IDE at design-time.

MyFunction1.Group := MyFunctionGroup;
MyFunction2.Group := MyFunctionGroup;
MyFunction3.Group := MyFunctionGroup;

And ... by assigning the same "TRtcFunctionGroup" instance to the "FunctionGroup" property of any number of "TRtcServerModule", "TRtcClientModule" and/or "TRtcScriptEngine" components, you can make all TRtcFunctions assigned to that "TRtcFunctionGroup" component accessible from all these components.

MyServerModule.FunctionGroup := MyFunctionGroup;
MyScriptEngine.FunctionGroup := MyFunctionGroup;
MyClientModule.FunctionGroup := MyFunctionGroup;

You can also assign a "Parent" Group to your "FunctionGroup", to make all Functions assigned to your "FunctionGroup" assessible from the "Parent" Function Group. The same works in the other direction as well, by using the "HelperGroup" property, giving your "FunctionGroup" access to all Functions assigned to the "HelperGroup".

The only thing you can NOT do, is to use a single "TRtcFunction" component with multiple "TRtcFunctionGroup" components. But since any Function Group can use its "Parent" property to give access to its functions to another Function Group, and any Function Group can use its HelperGroup property to gain access to functions from another Function Group, there is really no need for that.

Best Regards,
Danijel Tkalcec


Title: Re: How to add many of RtcFunctions to RtcFuntionGroup
Post by: xdu2050 on April 21, 2017, 03:04:02 PM
Of course, we can do this, but I want to add lot's of logic code like rtcScript in QuickStart , then add TRtcFunction will be a very troublesome thing, if TRtcFunctionGroup can directly load the script file, this will be perfect.
Code:
<?
function $fun1
begin
   ......
end;

function $fun2
begin
   ......
end;

function $fun3
begin
   ......
end;
?>


Title: Re: How to add many of RtcFunctions to RtcFuntionGroup
Post by: D.Tkalcec (RTC) on April 21, 2017, 03:55:56 PM
Functions written in a Script file are NOT the same as functions written in Delphi and assigned to a TRtcFunction component. Scripted functions are interpreted using the Scripting Engine, while functions written in Delphi and assigned to a TRtcFunction component are compiled into native executable code. These are two entirely different things.

If I understand you correctly now, you would like to write functions in a Script file and make your scripted functions accessible through a "TRtcFunctionGroup" component, just like you can access functions written in Delphi using the TRtcFunction component. Is that what you mean?

Best Regards,
Danijel Tkalcec


Title: Re: How to add many of RtcFunctions to RtcFuntionGroup
Post by: xdu2050 on April 25, 2017, 10:41:22 AM
Thx