Hello everyone,
I added a new feature to export report to file handle. With this you can export to stdout without temporal files, and using ony ram.
I like to share this with community, but I don't know how.
This is a source copy:
File lr_class.pas
Add to uses: pipes
type TfrReport add to public: function ExportToFileHandle(FilterClass: TfrExportFilterClass; FileHandle :THandle):Boolean;
function source:
function TfrReport.ExportToFileHandle(FilterClass: TfrExportFilterClass; FileHandle :THandle
): Boolean;
var
s: String;
i: Integer;
MemStream: TMemoryStream;
Outstream: TOutputPipeStream;
begin
// try to find a export filter from registered list
if (FilterClass=nil) and (fDefExportFilterClass<>'') then
begin
for i:=0 to ExportFilters.Count - 1 do
if (ExportFilters.FClassRef.ClassName=fDefExportFilterClass) then
begin
FilterClass := ExportFilters.FClassRef;
break;
end;
end;
if FilterClass=nil then
raise Exception.Create(sNoValidFilterClassWasSupplied);
OutStream := TOutputPipeStream.Create(FileHandle);
MemStream := TMemoryStream.Create();
FCurrentFilter := FilterClass.Create(MemStream);
try
CurReport := Self;
MasterReport := Self;
FCurrentFilter.OnSetup:=CurReport.OnExportFilterSetup;
if FCurrentFilter.Setup then
begin
FCurrentFilter.OnBeginDoc;
SavedAllPages := EMFPages.Count;
if FCurrentFilter.UseProgressbar then
with frProgressForm do
begin
s := sReportPreparing;
if Title = '' then
Caption := s
else
Caption := s + ' - ' + Title;
FirstCaption := sPagePreparing;
Label1.Caption := FirstCaption + ' 1';
OnBeforeModal := @ExportBeforeModal;
Show_Modal(Self);
end else
ExportBeforeModal(nil);
fDefExportFilterClass := FCurrentFilter.ClassName;
Result:=true;
MemStream.Seek(0, soBeginning);
OutStream.CopyFrom(MemStream, MemStream.Size - 1);
end
else
Result:=false;
finally
//is necessary to destroy the file stream before calling FCurrentFilter.AfterExport
//to ensure the exported file is properly written to the file system
OutStream.Free;
MemStream.Free;
end;
FCurrentFilter.Stream := nil;
if Result then
FCurrentFilter.AfterExport;
FreeAndNil(FCurrentFilter);
end;
Is posibble add that to official sources?
How?
Thanks!