Newsgroups : Borland : borland.public.delphi.internet.winsock : 2005 Apr : Indy9 idHTTPServer - how to generate thread safe GIF

www.cryer.info
Managed Newsgroup Archive

Indy9 idHTTPServer - how to generate thread safe GIF

Subject:Indy9 idHTTPServer - how to generate thread safe GIF
Posted by:"Ivan Mhitarov" (vanmh..@urltoy.com)
Date:Tue, 5 Apr 2005 17:49:39

Hi,

I'm using D7 with Indy 9.00.10

I have an empty form with idHTTP Server which must serve requests like GET
/state_img.gif?id=XXX, generate the GIF image based on XXX and send it back
to the browser.
When I'm trying to do something like this:

Var CS : TCriticalSection
[......]
procedure TForm1.IdHTTPServerCommandGet(AThread: TIdPeerThread;
  ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
Var St : Integer;
    B  : TBitMap;
    G  : TJvGIFImage;
    M  : TMemoryStream;
begin
  CS.Enter;
  St:=StrToIntDef(ARequestInfo.Params.Values['id'], 0);
  Sleep(50);
  B:=TBitMap.Create;
  B.Width:=16;
  B.Height:=16;
  B.PixelFormat:=pf8bit;
  // Drawing on BitMap B
  G:=TGIFImage.Create;
  Try
    G.Assign(B);
    M:=TMemoryStream.Create;
    Try
      G.SaveToStream(M);
      M.Position:=0;
      AResponseInfo.RawHeaders.Clear;
      AResponseInfo.RawHeaders.Add('Cache-Control: no-store, no-cache,
must-revalidate');
      AResponseInfo.RawHeaders.Add('Cache-Control: post-check=0,
pre-check=0');
      AResponseInfo.RawHeaders.Add('Pragma: no-cache');
      AResponseInfo.ResponseNo := 200;
      AResponseInfo.ContentType := 'image/gif';
      AResponseInfo.FreeContentStream := True;
      AResponseInfo.ContentStream := M;
    Except
      M.Free;
    End;
  Finally
    G.Free;
    B.FreeImage;
    B.Free;
    CS.Leave;
  End;

I have some (more than 30%) dropped images and EOutOfResources Access
Violations.
How I must do it better?

Replies:

www.cryer.info
Managed Newsgroup Archive