Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get data for FastReport (Delphi) from an TEdit?

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.

like image 638
kimberlywemr Avatar asked Oct 13 '19 16:10

kimberlywemr


2 Answers

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].

enter image description here

like image 154
Fabrizio Avatar answered Nov 02 '22 23:11

Fabrizio


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.

enter image description here

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.

like image 34
Zhorov Avatar answered Nov 02 '22 23:11

Zhorov