I followed a tutorial here for how to include a file inside of an EXE. While I successfully got a PNG image compiled, when it comes to using it, I’m unsuccessful.
MyResources.rc
LOGO_PNG RCDATA Resources\Logo.png
MyConsoleUnit.pas
const
RES_LOGO_PNG = 'LOGO_PNG';
implementation
{$R *.dfm}
{$R 'MyResources.res' 'MyResources.rc'}
Now this is where things get a little confusing for me. I have to work with all streams, no files. I have embedded this PNG image Logo.png as this resource to be passed back as content (as a stream) when /Logo.png is requested from the web server. I also followed a very basic tutorial for this:
procedure TMyWebConsole.MyWebConsoleLogoAction(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var
RS: TResourceStream;
begin
RS := TResourceStream.Create(HInstance, RES_LOGO_PNG, RT_RCDATA);
try
Response.ContentType:= 'image/png';
RS.SaveToStream(Response.ContentStream);
finally
RS.Free;
end;
end;
The problem is, when this function is called (at SaveToStream) I get an access violation. The web browser on the client end receives the same error message as the content of the “PNG file”.

So why is it doing this? What am I doing wrong?
You’re accessing a null pointer. It’s probably
Response.ContentStream, which is a property you’re supposed to assign, not read. The documentation says this:That suggests the ContentStream might be nil. Thus, you need to assign a value to it if you want to use it:
The documentation further explains: