-1

I need help in this code

This is all code

Request: TIdHTTPRequestInfo

Response: TIdHTTPResponseInfo

JQuery: TResourceStream

procedure TServer.ActiveServer;
begin
  DefaultPort := 8117;
  Active := True;
  OnCommandGet := FServerCommandGet;
  JQuery := TResourceStream.Create(HInstance,'JQuery',RT_RCDATA);
end;

function TServer.FindFiles: Boolean;
var
  Stream : TStream;
begin
  if Request.Document = '/jquery.js' then
  begin
    Response.ContentType := 'application/x-javascript';
    Stream := TStream.Create;
    Stream.Position := 0;
    Stream.CopyFrom(JQuery,JQuery.Size);
    Response.ContentStream := Stream;
    Result := True;
  end else
    Result := False;
end;

error : TStream.Seek not implemented

The problem is in the copy TResourceStream in TStream

NINO SAN
  • 1
  • 3

1 Answers1

2

TStream is an abstract class so it cannot be used directly, you must use one it's descendants. TResourceStream for example.

P.S : I see that you are dealing with Indy, no need to free the stream when assigned to ContentStream, Indy will handle that for you.

function TServer.FindFiles: Boolean;
var
  Stream : TResourceStream;
begin
  if Request.Document = '/jquery.js' then
  begin
    Response.ContentType := 'application/x-javascript';
    Response.ContentStream := TResourceStream.Create(HInstance, 'JQuery', RT_RCDATA);
    Result := True;
  end else
  begin
    Result := False;
  end;
end;
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
whosrdaddy
  • 11,720
  • 4
  • 50
  • 99