0
votes

I am looking for a simple example or a reference to print items from a listview using fastreport. For example: I have a listview that has three columns: id, name and marks. The listview has n number items each containing id, name and marks of individual students. I need to print the whole listview using fastreport in a tabular format. I googled but couldn't find an exact sample for my scope. Similarly, I couldn't find any documentation regarding this in fastreport demo. I am using Delphi XE8 with default installed fastreport version.

1
You should use frxUserDataSet. I don't know whether DelphiXE8 installation has fastreport..\demo folder. If there is see PrintStringList demo.Val Marinov
It isn't there. I did search for such question in SO. Btw I am new in using reporting tool.Rabi Jayasawal
@ValMarinov I found a similar question here: stackoverflow.com/questions/23535533/… But the answer didn't seem to be clear to me.Rabi Jayasawal
Ок. I will try to write a brief "demo"Val Marinov

1 Answers

2
votes

For demonstration purposes.

Place on the form the following components:

  • TButton;
  • TListView;
  • frxReport;
  • frxUserDataSet;

Double click on frxReport. In the Fastreport designer do

insert ReportTitle, MasterData and PageFooter bands.

Press Report => Data menu items. Check frxUserDataSet check box and press OK button.

Assign MasterData band with frxUserDataSet as double click on MasterData band and select frxUserDataSet, then press 'OK' button.

In MasterData band insert Text object (Memo). In Memo write [element].

Designer should look like this :

enter image description here

Now we can write some code :

procedure TForm8.FormCreate(Sender: TObject);
var
  I: Integer;
  Li : TlistItem;
begin
  // Just to fill some data in ListView 
  for I := 1 to 10 do
   begin
    Li := ListView1.Items.Add;
    LI.Caption := 'Col ' + IntToStr(i);
   end;

end;

In frxReport1 OnGetValue event write for example :

procedure TForm8.frxReport1GetValue(const VarName: string; var Value: Variant);
begin
  if CompareText(VarName, 'element') = 0 then
    Value := ListView1.Items[frxUserDataSet1.RecNo].Caption;
end;

And now print data

procedure TForm8.Button1Click(Sender: TObject);
begin
  frxUserDataSet1.RangeEnd := reCount;
  frxUserDataSet1.RangeEndCount := ListView1.Items.Count;
  frxReport1.ShowReport();
end;

The result after Button1 is pressed:

enter image description here

Note : In this answer is used part of FastReport PrintStringList demo.