If you want to have the ByteStream inside your 'params' Array at element 0, you should call the NewByteStream(0) method on the Array object (which would be "lParams" in your example above). So, here is that code for the Client (I'm avoiding the use of the "with" statement here for clarity reasons) ...
procedure TRTCControl.RTCUpload(<...snip...>
arParams : array of variant;
aStream : TMemoryStream;
<...snip...>);
var
i : integer;
lParams : TRtcArray;
begin
{ the next line is similar to calling RtcClientModule1.Data.NewFunction('f_UploadFileToServer'),
but it also clears the "Data" object, in case they it was left assigned, which could happen
in case of an exception while preparing any previous remote function call ... }
RtcClientModule1.Prepare('f_UploadFileToServer');
{ the next line creates an Array as the "Params" parameter for the remote function
and is basically the exact same thing as what you did in your example code, but
uses the "Param" object on the RtcClientModule instead of using the "with" statement
to imply access to the TRtcFunctionInfo object created with a call to Data.NewFunction() ... }
lParams := RtcClientModule.Param.NewArray('Params');
{ the next line
creates a ByteStream in the "Params" Array at index 0,
which is what you actually whated to do, but have instead created a ByteStream
as a 'stream' parameter of the remote function object using NewByteStream('stream') ... }
lParam.NewByteStream(0); { the next 2 lines move the source "aStream" to the beginning and
then copy the contents of the "aStream" into the ByteStream ... }
aStream.Seek(0,soFromBeginning);
lParam.asByteStream[0].CopyFrom(aStream, aStream.Size);
{ the rest of your Client-side code was correct from the start ... }
if length(arParams) > 0 then
for i:= low(arParams) to high(arParams) do
begin
lParams.asValue[i+1] := arParams[ i ];
end;
<...snip...>
Now, you have the Stream at index 0 of your 'params' array (and your other parameters at indexes 1 and above), so you could do something like this on the Server to read it all ...
var lArray:TRtcArray; // temp variable for our "params" array
aStream:TStream; // wherever we want the Stream
begin
if Param.isType['params']=rtc_Array then // make sure we have received an Array
begin
lArray:=Param.asArray['params'];
if lArray.Count > 0 then
for i:= 0 to lArray.Count-1 do
if lArray.isType[ i ]=rtc_ByteStream then
begin
// aStream :=
<---- YOUR CODE COMES HERE
{ <----
HERE, you need to set "aStream" to your destination Stream! Since you have sent some data to the Server, I guess you know what you want to do with it.
The stream contents is here and below is the code to copy it into any other TStream,
but copying it into some TStream which you are just going to destroy makes no sense.
Anway ... Here is to code which would copy that Stream to "aStream" (which you have to initialize before) ... }
lArray.asByteStream[ i ].Seek(0,soFromBeginning);
aStream.CopyFrom(lArray.asByteStream[ i ],lArray.asByteStream[ i ].Size);
end
else
<SomethingThatExpectsYourVariantValue> := lArray.asValue[ i ];
end;
end;
Best Regards,
Danijel Tkalcec