Datasnap Remote method returns Tstream positive solution
Datasnap Remote method returns Tstream, if the data size exceeds 32K will be an error. Many delphier are planted on the top and even begin to doubt the viability of Tstream returning data.
Because the Datasnap remote method returns Tstream, the packet size has a maximum limit of 32K.
How to solve? The client wants to do and package the processing.
functionCopyStream (Constastream:tstream): Tmemorystream;Constlbufsize=$F;varlbuffer:tbytes; Lreadlen:integer;beginResult:=Nil;ifAstream =Nil ThenExit; Result:= Tmemorystream.Create;TryifAstream.size =-1 ThenbeginSetLength (Lbuffer, lbufsize);RepeatLreadlen:= Astream.read (lbuffer[0], lbufsize);ifLreadlen >0 ThenResult.writebuffer (lbuffer[0], lreadlen);ifLreadlen < Lbufsize Then Break;untilLreadlen <lbufsize;EndElseResult.copyfrom (Astream,0); Result.position:=0;exceptResult.free;End;End; procedureTform1.btnqry3click (sender:tobject);varLstream:tstream; Lmemstream:tmemorystream;beginDatasource1.dataset:=FDMemTable1; Lstream:= methods. QUERYSQL3 ('0','SELECT * from T1');ifLstream <>Nil ThenbeginLmemstream:=CopyStream (Lstream); Fdmemtable1.loadfromstream (Lmemstream, tfdstorageformat.sfbinary); Lmemstream.free;End;End;
Datasnap Remote method return Tstream positive solution (to chant South brother)