从TEdit组件获取数据到FastReport(Delphi)的方法是什么?

6

我使用FastReport创建了一个报告,但我只知道从数据库获取数据到该报告的方法,我想从TEdit获取数据,而且我不想存储任何东西,只需在TEdit中输入并单击按钮(fastreport.preview)+ 打印 + 完成。
我该如何做?
请说明,我是Delphi和FastReport的新手。


你可以将该值添加到内存数据集中... - R. Hoek
2个回答

4
您可以按照以下方式使用您的 TfrxReport 组件的 OnGetValue 事件:
procedure TForm1.frxReport1GetValue(const VarName: string; var Value: Variant);
begin
  if(VarName = 'MyVariable') then
  begin
    Value := Edit1.Text;
  end;
end;

然后你只需要向报告中添加一个备忘录项,并将其值设置为[MyVariable]

enter image description here


优雅的解决方案!谢谢,我已经搜索了几个小时了。 - t1f

3
一种可能的方法是在运行时访问TfrxReportTfrxMemoView组件。请注意,当您没有数据集时,Master Data带不会被打印,因此您应该使用另一个带。
您可以使用以下代码作为基本示例。只需在TfrxReport组件上放置一个TfrxReportTitle带(命名为'ReportTitle1')和一个TfrxMemoView文本对象(命名为'Memo1')。

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;

注意:这是一个可用的示例,已经在FastReport 4.7中测试过。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接