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.
JimmyCAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.