Well in that case, we literally pass the response object into our Delphi COM object as an OleVariant
 
The code on the web goes something like:
BinaryObject.WriteToAsp response
 
In the Delphi COM object:
 
procedure TBinaryObject.WriteToASP(response: OleVariant);
var
  rs : Recordset;
  aField : Field20;
  chunk : Variant;
  size : integer;
begin
  try
    rs := // Get recordset
    aField := rs.Fields[0];
    size := CHUNK_SIZE;
    while size = CHUNK_SIZE do
    begin
      chunk := aField.GetChunk(CHUNK_SIZE);
      if chunk = null then exit;
      response.BinaryWrite(chunk);
      response.Flush;
    end;
  finally
    if Assigned(rs) then rs.Close;
  end;
end;
 
Stephen
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]On Behalf Of Jeremy Coulter
Sent: Thursday, 19 August 2004 11:28 a.m.
To: NZ Borland Developers Group - Delphi List
Subject: RE: [DUG] Streaming PDF

Hi Steve. Well its ASP of a kind. Found a wee program called BABY ASP Server that is compatible witn almost 100% ASP code, BUT it does not need ASP.DLL, IIS or PWS to be installed. Its a great little tool, and even runs on win98 !
 
the guy says I can access the ASP object and use the ASP  response object, but it didnt work for me and he was going to investigate it more.
I am considering using PWS and IIS, more likely IIS, now because I really need to stream the PDF, and as you pointed out, I can access the ASP response object.
 
Thanks, Jeremy
-----Original Message-----
From: "Witherden, Stephen" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>, "NZ Borland Developers Group - Delphi List" <[EMAIL PROTECTED]>
Date: Thu, 19 Aug 2004 10:24:14 +1200
Subject: RE: [DUG] Streaming PDF

Dear Jeremy
 
1. Is it possible you have compression enabled on your web servers? That caused us no end of problems with PDF documents.
 
2. If you're using ASP or ASP.Net you can write directly to the response stream in Delphi. And you can use GetChunk() to get parts of a BLOB from the database.
The code we use for that sort of stuff goes something like this.
I am afraid we had to create the variant array "manually". If anyone has a more efficient way, I am all ears :)
 
procedure TBinaryObject.WriteToWithCommit(const stream: IUnknown);
var
  rs : Recordset;
  aStream : IStream;
  aField : Field20;
  chunk : Variant;
  buffer : String;
  i, size : integer;
begin
  try
    if Stream.QueryInterface(IStream, aStream) <> 0 then raise exception.Create('Invalid stream passed in to CSL2000.BinaryObject.WriteTo');
    rs := // get recordset from database;
    aField := rs.Fields[0];
    size := CHUNK_SIZE;
    SetLength(buffer,CHUNK_SIZE);
    while size = CHUNK_SIZE do
    begin
      chunk := aField.GetChunk(CHUNK_SIZE);
      if chunk = null then exit;
      size := VarArrayHighBound(chunk,1) - VarArrayLowBound(chunk,1);
      for i := 0 to size do
        buffer[i+1] := Chr(Ord(Byte(chunk[i]))); // Don't know why we have to do this :(
      aStream.Write(PChar(buffer), size+1, @size);
      aStream.Commit(STGC_DEFAULT);
    end;
  finally
    if Assigned(rs) then rs.Close;
  end;
end;
 
Stephen
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]On Behalf Of Jeremy Coulter
Sent: Thursday, 19 August 2004 9:24 a.m.
To: [EMAIL PROTECTED]; 'NZ Borland Developers Group - Delphi List'
Subject: RE: [DUG] Streaming PDF

MORE investigations revel that its not so much missing chars as just not displaying correctly for NO apparent reason that I can see.
Agh bugger it, I will just use a wee CGI app. :-)
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jeremy Coulter
Sent: Thursday, 19 August 2004 07:23
To: [EMAIL PROTECTED]
Subject: [DUG] Streaming PDF

Hi All.
I want to stream a PDF from a COM DLL to a webpage.
I can do this fine from a CGI app or an ISAPI DLL which nicely handles this, but I need to convert the file to an OLEVarient (I am assuming here) which then gets passed back to an ASP page.
I want to stream rather than a link, or redirect to the file, so that I dont have to deal with the potentually large number of PDF files that would be generated.
 
At the moment, my code seems to work, and I am using a bit of code that I found that will stream an image, but it wont work for a PDF. On further investigation, it seems to be missing chars which prevent it form displaying correctly, and YES I am setting teh ContentType and also adding a header with "Content-Disposition", "inline;filename=form.pdf" in it.
Here is my code, Can anyone spot the problem?
 
Thanks, Jeremy  :-
 
function TctSecurity.PDF_Test: OleVariant;
var
  v: OleVariant;
  ptr: Pointer;
  S: TMemoryStream;
begin
  s := TMemoryStream.Create;
  try
    s.LoadFromFile('e:\Test6.pdf');
    s.Position := 0;
 
    v := VarArrayCreate ( [0, s.Size - 1], varByte );
    ptr := VarArrayLock ( v );
    try
      s.ReadBuffer ( ptr^, s.Size );
    finally
      VarArrayUnlock ( v );
    end;
 
    Result:=v;
  finally
    s.Free;
  end;
end;
_______________________________________________
Delphi mailing list
[EMAIL PROTECTED]
http://ns3.123.co.nz/mailman/listinfo/delphi

Reply via email to