I created a report using FastReport, but the only way I know to get data to that report is from a database, I want to get data from a TEdit
and I don't want to store anything, just writing in TEdit
+ click on the button (fastreport.preview) + print and Done.
How can I do that ?
Please explain am new with Delphi and FastReport.
6
votes
You could add the value to a memory dataset...
– R. Hoek
2 Answers
4
votes
You can use the OnGetValue
event of your TfrxReport
component as follows:
procedure TForm1.frxReport1GetValue(const VarName: string; var Value: Variant);
begin
if(VarName = 'MyVariable') then
begin
Value := Edit1.Text;
end;
end;
Then you just need to add a memo item to the report and set its value to [MyVariable]
.
2
votes
One possible approach is to access the TfrxReport
and TfrxMemoView
components at runtime. Note, that when you don't have a dataset, the Master Data
band won't be printed, so you should use another band.
You may use the following code as a basic example. Just place one TfrxReportTitle
band (named 'ReportTitle1'
) and one TfrxMemoView
text object (named 'Memo1'
) on your TfrxReport
component.
procedure TfrmMain.btnReportClick(Sender: TObject);
var
memo: TfrxMemoView;
band: TfrxReportTitle;
begin
// Get the band
band := (rptDemo.Report.FindObject('ReportTitle1') as TfrxReportTitle);
// Create a memo
memo := TfrxMemoView.Create(band);
memo.CreateUniqueName;
memo.ParentFont := True;
memo.Text := edtReport.Text;
memo.SetBounds(100, 1, 100, 16);
memo.HAlign := haLeft;
memo.AutoWidth := False;
// Use existing memo
memo := (rptDemo.Report.FindObject('Memo1') as TfrxMemoView);
memo.Text := edtReport.Text;
// Preview report
rptDemo.ShowReport(False);
end;
Notes: This is a working example, tested with FastReport 4.7.