Hi
I’m using RemObjects and Delphi (Alexandria).
We have a service method which returns a pdf file to a web client. The code is below:
function TDocs.getDoc(id: Integer): Binary;
var
lStream: TMemoryStream;
lFilename: string;
begin
lStream := TMemoryStream.Create;
try
Result := TROHttpApiResult.Create(HTTP_200_code,
id_ContentType_application_pdf,'',false);
try
GetDoc(id, lStream); // lstream is var
result.LoadFromStream(lStream);
finally
FreeAndNil(lStream);
end;
end;
It works flawlessly.
Now, we need to return several pdfs in one single method. As PDF is a tricky to concatenate (it’s not just adding one stream to another), we’ve chosen to return an array of binary and concatenate in the client (using javascript libraries).
So we changed the method:
TDocuments = TRoArray<binary>;
function TDocs.getDocs(id: Integer): TDocuments;
var
lStream: TMemoryStream;
lFilename: string;
docsToPrint: TPDFInfoCollection;
i: integer;
pdf: TRoBinaryMemoryStream;
begin
docsToPrint := TDocsCollection.Create; // just a collection of pdf information
try
Result := TDocuments.Create;
docsToPrint := getDocs( id );
try
for i := 0 to docsToPrint.Count-1 do begin
lStream := TMemoryStream.Create;
pdf := TRoBinaryMemoryStream.Create;
try
GetDoc(docsToPrint[i], lStream); // lStream is var
result.Add(pdf.LoadFromStream(lStream)); // error here
// there is no overload method of Add that can be called with these arguments
finally
FreeAndNil(lStream);
end;
end;
finally
FreeAndNil( itensImprimir );
end;
end;
Is there something I’m missing here? How can I return an array of binary?