08-21-2018, 01:40 AM
(08-02-2018, 11:41 PM)Alexandre Machado Wrote: Hi,
unit is IWServerInternalFiles.pas. It implements TIWServerInternalFiles class which handles a list of resources kept in streams (TMemoryStream instances).
It is accessible via gInternalFiles instance declared in the same unit.
You can add custom memory streams to the list like:
procedure AddStream(aStream: TMemoryStream; AResName, AFileName: string);
You need to provide a unique AResName and a AFileName which can be basically anything. Example:
gInternalFiles.AddStream(MyMemStream, 'MY_TEMPLATE', 'mytemplate');
then you retrieve it using ResourceAsStream Method like
myStream := gInternalFiles.ResourceasStream('MY_TEMPLATE');
You are responsible for freeing myStream instance. However, if you intend to use it in a template, it doessn't need to be freed (the tamplate engine frees it for you).
Please let me know if you need further help
Thanks. I am working on a proof in concept and have been able to load a stream from a file to use in the template processor using the beforeProcess event; however, I can not seem to be able to load from the ServerInternalFiles.
Here is the code that I am trying to use but it just gives me a blank page.
procedure TMainForm.tpBeforeProcess(var VTemplate: TStream);
var
lTemplateMemStream : TMemoryStream;
begin
try
lTemplateMemStream := TMemoryStream.Create;
lTemplateMemStream.Position := 0;
lTemplateMemStream.LoadFromFile('STEP_HTML.html');
gInternalFiles.AddStream(lTemplateMemStream,'TEST_RES','test');
VTemplate.Free;
VTemplate := Tstream.Create;
VTemplate := gInternalFiles.ResourceAsStream('TEST_RES');
finally
lTemplateMemStream.Free;
end;
end;
The following code will load a template from a file into the template processor and works, but does not use the ServerInternalFiles.
procedure TMainForm.tpBeforeProcess(var VTemplate: TStream);
begin
VTemplate.Free;
VTemplate := TFileStream.Create('STEP_HTML.html', fmOpenRead + fmShareDenyWrite);
TFileStream(VTemplate).Seek(0, soFromBeginning);
end;
Any help on what I am doing wrong on the first procedure would be appreciated.

