Reputation: 33
I am trying to build a finance software in Delphi. For the database I used Interbase which I am using it for the first time since I used Firebird before.
Any way I am 80% done but I face a problem: I found that I can create a report with .fr3
(FastReport) inside the database - everything is Ok.
I didn't find any solution how to load a stored report from the database into the project - something along the lines of this:
sReportFile := LoadFileFromDatabase ('ReportFiles', 'ReportFile', StrToInt(sID));
Thank you for any pointers.
Upvotes: 0
Views: 1995
Reputation: 544
Try
procedure TForm1.frxReport1LoadTemplate(Report: TfrxReport;
const TemplateName: String);
var
memStream:TMemoryStream;
BookMark: TBookmark;
begin
try
memStream:=TMemoryStream.Create;
BookMark:=ADOTable1.GetBookmark;
if ADOTable1.Locate('TemplateName', TemplateName, [loCaseInsensitive]) then
begin
ADOTable1ReportBLOB.SaveToStream(memStream);
memStream.Position:=0;
Report.LoadFromStream(memStream);
end;
ADOTable1.GotoBookmark(BookMark);
finally
memStream.Free;
ADOTable1.FreeBookmark(BookMark);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
memStream:TMemoryStream;
begin
if OpenDialog1.Execute then
try
memStream:=TMemoryStream.Create;
frxReport1.LoadFromFile(OpenDialog1.FileName);
frxReport1.SaveToStream(memStream);
memStream.Position:=0;
ADOTable1.Insert;
ADOTable1TemplateName.AsString:=ExtractFileName(OpenDialog1.FileName);
ADOTable1ReportBLOB.LoadFromStream(memStream);
ADOTable1.Post;
finally
memStream.Free;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
memStream:TMemoryStream;
begin
memStream:=TMemoryStream.Create;
frxReport1.InheritFromTemplate(ADOTable1TemplateName.AsString, imDelete);
try
memStream:=TMemoryStream.Create;
frxReport1.SaveToStream(memStream);
memStream.Position:=0;
ADOTable1.Insert;
ADOTable1TemplateName.AsString:=Edit1.Text;
ADOTable1ReportBLOB.LoadFromStream(memStream);
ADOTable1.Post;
finally
memStream.Free;
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
var
memStream:TMemoryStream;
begin
try
memStream:=TMemoryStream.Create;
ADOTable1ReportBLOB.SaveToStream(memStream);
memStream.Position:=0;
frxReport1.LoadFromStream(memStream);
frxReport1.DesignReport();
finally
memStream.Free;
end;
end;
function TForm1.frxDesigner1SaveReport(Report: TfrxReport;
SaveAs: Boolean): Boolean;
var
memStream:TMemoryStream;
begin
if not SaveAs then
try
memStream:=TMemoryStream.Create;
frxReport1.SaveToStream(memStream);
memStream.Position:=0;
ADOTable1.Edit;
ADOTable1ReportBLOB.LoadFromStream(memStream);
ADOTable1.Post;
finally
memStream.Free;
end;
end;
You may contact FR support and get full demo project
Upvotes: 3
Reputation: 47694
Assuming that the report is stored inside a bob field of one of the tables in the database, you can simply create a stream with TDataSet.CreateBlobStream
and use that with TfrxReport.LoadFromStream
.
Upvotes: 0