[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 393
  • Last Modified:

ASP in Delphi

Hi, I want to create an ASP serverobject in Delphi 5. It should return a jpeg-image so I can use this ASP code:

<% Set Image = Server.CreateObject("MyServerObject.MyASPImage")
Response.ContentType = "image/jpeg"
Response.BinaryWrite Image.Image
%>

Does anyone know how to do this? Only a working solution/example deserves points

Jimmy.
0
JimmyC
Asked:
JimmyC
  • 4
  • 3
  • 2
1 Solution
 
RadlerCommented:
Try this:

Img:=TJPEGImage.Create;
Img.LoadFromFile( '????' );
Strm:=TMemoryStream.Create;
try
   Img.SaveToStream( Strm );
   Strm.Position:=0;
   Response.ContentType:='image/jpeg';
   Response.ContentStream:=Strm;
   Response.SendResponse;
finally
   //Dont call Strm.Free before AfterDispatch ( thread fail )
end;
finally
  Img.Free;
end;

T++, Radler.
0
 
JimmyCAuthor Commented:
That won't work because that's CGI/ISAPI etc....

I am talking about ASP server objects here.
What I want to do is something like ASPImage (see http://www.serverobjects.com/products.htm#AspImage). When I generated a type library in Delphi of this object it says that the returnvalue of the image propertie's get-function is 'OleVariant'. So I need to return the stream of the image in the OleVariant or something like that.

function TMyASPImage.Get_Image: OleVariant;
begin
  result := ......
end;
0
 
JimmyCAuthor Commented:
Thanks for your response of course  :o)
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
RadlerCommented:
Well,
here I not have Delphi5. Wait I go to another room. OK ?
But I imagine that you will need Mime encode the image stream  to put the result at a Olevariant.

T++, Radler.
0
 
EpsylonCommented:
Well, since ASP does the MIME encoding part you just need to copy the file into a VariantArray. Your function should look something like this:


function TMyASPImage.Get_Image: OleVariant;
var ms: TMemoryStream;
    A: Variant;
    i: Integer;
    pbyte: PByteArray;
begin
  ms := TMemoryStream.Create;
  ms.LoadFromFile('c:\inetpub\wwwroot\test\image.jpg');
  A := VarArrayCreate([0, ms.Size - 1], varByte);
  pbyte := ms.Memory;
  for i := 0 to ms.Size - 1 do
    A[i] := pbyte[i];
  Result := A;
  ms.Free;
end;


I just tested it myself and it works!

Regards,

Epsylon.
0
 
RadlerCommented:
I'm in doubt if this will work Epsylon. A #0 or worse #0#0 are possibilities at the data stream. A string receiving these values maybe trunc your content.

T++, Radler.
0
 
JimmyCAuthor Commented:
Hey, this just works great!!!

You are my man!! I tried it with over 100 different pictures and it works just perfectly!

Radler: why are #0's a problem? In all my jpeg files, that I have viewed with a hex viewer, there are lots of zeros. The OleVariant is not a string. It's a binary array here. Strings are passed with the WideString type.....
0
 
RadlerCommented:
Sorry, I dont pay attention to
A := VarArrayCreate([0, ms.Size - 1], varByte); //OK !

T++, Radler.
0
 
EpsylonCommented:
Now this problem has been solved I guess we can have a peacefull Christmas time.

Merry Christmas
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now