D.Tkalcec (RTC)
|
|
« Reply #1 on: December 28, 2016, 09:32:39 AM » |
|
1. With Result.asObject:=rtcDS, you are assigning a pointer to the original rtcDS object to the Result instance (not a COPY) and should NOT free the rtcDS object afterwards, or you will be facing all sorts of problems, like data contained in rtcDS NOT being sent to the Client and/or Access Violations on the Server. The easiest way to ensure you won't accidentally free rtcDS (you are manually doing it in your code - two times), you should set it to NIL immediately after the assignment, like this ...
Result.asObject:=rtcDS; rtcDS:=nil;
2. If you want Exceptions which you are manually handling inside your remote function code on the Server to be forwarded to the Client, you have to re-raise them (using "raise"), like this ...
except on E:EDatabaseError do begin //If something went wrong we free the created TRtcDataSet object memo1.Lines.Add('err'); rtcDS.Free; raise; // this will re-raise the exception end;
3. If your Server is MultiThreaded and you want to access the GUI from a remote function (for example, to access a "TMemo" component on your Form), you have to synchronize your remote function with the Main Thread. To synchronize the entire remote function with the Main Thread, you can add this like at the top of your remote function event, immediately after "begin" ...
procedure TfrmMainMarcaje.getnewrowsExecute(Sender: TRtcConnection; Param: TRtcFunctionInfo; Result: TRtcValue); var rtcDS: TRtcDataSet; qr:tfdquery; begin if Sender.Sync(getnewrowsExecute,Param,Result) then Exit;
4. If you receive a Result with the type rtc_Exception on the Client (Result.isType=rtc_Exception), it means that an Exception was raised inside the remote function implemented on the Server and the Exception was left unhandled or was re-raised. In that case, Result.asException will contain the Exception Message. That is NOT an indication of connection problems with the Server (see the ShowMessage line in your Client-side Result event). In case of connection problems, the RequestAborted event will be triggered on the TRtcResult component assigned to receive the result from the Server, and ... the OnResponseAbort event will be triggered on the TRtcClientModule component posting the request. These are the places where you can handle connection-related problems.
Best Regards, Danijel Tkalcec
|