设为首页 加入收藏

TOP

RTC Remote Functions - working with flexible structures(一)
2017-10-10 12:03:38 】 浏览:832
Tags:RTC Remote Functions working with flexible structures

 

Author RTC Remote Functions - working with flexible structures
Danijel Tkalcec [RTC]

01.06.2006 20:27:57
Registered user
You can form your structure as simple and as complex as you want. RTC uses highly flexible format, so that you can define virtually any structure you want, even call remote function which will call other remote functions to get parameters.

You can store multiple values in each element by using newRecord, newArray or newDataSet. Here is one example of creating an array called “numbers”, which will hold a number of records (here 0 to 9) with “x:integer; dt:TDateTime” and send this to a remote function named “callme”.

This is the client-side code:
with myClientModule do
  begin
  with Data.newFunction(’callme’) do
    begin
    // prepare an array to send as parameter
    with NewArray(’numbers’) do
      begin
      for I := 0 To 9 do
        begin
        // each item inside this array
        // will be a new record
        with newRecord(I) do
          begin
          asInteger[’X'] := I;
          asDateTime[’dt’] := Now;
          end;
        end;
    end;
  Call(myResult);
  end;

And on the server side, you can access all data inside this array like this:
// need to make sure this parameter is an array …
if isType[’numbers’]=rtc_Array then
  with asArray[’numbers’] do
    begin
    // loop through all elements
    for I := 0 to Count-1 do
      begin
      // make sure this element is a record
      if isType[i]=rtc_Record then
        with asRecord[I] do
          begin
          // read the data inside the record
          X := asInteger[’X'];
          dt := asDateTime[’dt’];
          end;
        end;
      end;

Whenever you expect to use complex types, you should use “isType” to check if that element really contains the data type you expect, so you don’t end up with access violations in case the element is not assigned (in which case asRecord, asArray and asDataSet would return NIL).

Using the same paradigm, you can write your remote function to return any complex structure back to the client. You will simply prepare the data for “Result” using the same newRecord, newArray and newD
首页 上一页 1 2 3 4 下一页 尾页 1/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇[笔记] 升級到 Delphi 10.2 Tokyo.. 下一篇Server calling functions on cli..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目