基本全是参考 fastreport的demo
代码如下unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, Grids, frxCross, frxClass;type
TForm1 = class(TForm)
frxReport1: TfrxReport;
frxCrossObject1: TfrxCrossObject;
StringGrid1: TStringGrid;
BitBtn1: TBitBtn;
procedure FormCreate(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure frxReport1BeforePrint(Sender: TfrxReportComponent);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
var
i:integer;
j:integer;
begin
for i:=1 to StringGrid1.RowCount -1 do
for j:=1 to StringGrid1.ColCount -1 do
StringGrid1.Cells[i,j]:=IntToStr(i*j);
end;procedure TForm1.BitBtn1Click(Sender: TObject);
begin
//frxReport1.co
self.frxReport1.ShowReport ;
end;procedure TForm1.frxReport1BeforePrint(Sender: TfrxReportComponent);
var
Cross: TfrxCrossView;
i, j: Integer;
begin
//showmessage('1');
if Sender is TfrxCrossView then
begin
Cross := TfrxCrossView(Sender);
for i := 1 to StringGrid1.RowCount -1 do
for j := 1 to StringGrid1.ColCount -1 do
Cross.AddValue([i], [j], [StringGrid1.Cells[i - 1, j - 1]]);
end;
end;end.他NN的运行起来点击按钮可以打开预览窗口,但是里面什么都没有,而且frxReport1BeforePrint事件貌似不执行,哪里有问题呢?
代码如下unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, Grids, frxCross, frxClass;type
TForm1 = class(TForm)
frxReport1: TfrxReport;
frxCrossObject1: TfrxCrossObject;
StringGrid1: TStringGrid;
BitBtn1: TBitBtn;
procedure FormCreate(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure frxReport1BeforePrint(Sender: TfrxReportComponent);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
var
i:integer;
j:integer;
begin
for i:=1 to StringGrid1.RowCount -1 do
for j:=1 to StringGrid1.ColCount -1 do
StringGrid1.Cells[i,j]:=IntToStr(i*j);
end;procedure TForm1.BitBtn1Click(Sender: TObject);
begin
//frxReport1.co
self.frxReport1.ShowReport ;
end;procedure TForm1.frxReport1BeforePrint(Sender: TfrxReportComponent);
var
Cross: TfrxCrossView;
i, j: Integer;
begin
//showmessage('1');
if Sender is TfrxCrossView then
begin
Cross := TfrxCrossView(Sender);
for i := 1 to StringGrid1.RowCount -1 do
for j := 1 to StringGrid1.ColCount -1 do
Cross.AddValue([i], [j], [StringGrid1.Cells[i - 1, j - 1]]);
end;
end;end.他NN的运行起来点击按钮可以打开预览窗口,但是里面什么都没有,而且frxReport1BeforePrint事件貌似不执行,哪里有问题呢?
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, StdCtrls, FR_Class, FR_Desgn, FR_BarC, FR_DSet, FR_DBSet,
FR_Cross;type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
frReport1: TfrReport;
Button1: TButton;
frDesigner1: TfrDesigner;
Dataset: TfrUserDataset;
procedure FormCreate(Sender: TObject);
procedure frReport1BeforePrint(Memo: TStringList; View: TfrView);
procedure frReport1GetValue(const ParName: String;
var ParValue: Variant);
procedure Button1Click(Sender: TObject);
procedure DatasetCheckEOF(Sender: TObject; var Eof: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
var
i:integer;
j:integer;
begin
for i:=1 to StringGrid1.RowCount -1 do
for j:=1 to StringGrid1.ColCount -1 do
StringGrid1.Cells[i,j]:=IntToStr(i*j);
end; procedure TForm1.frReport1BeforePrint(Memo: TStringList; View: TfrView);
var
Cross : TfrCrossView;
i, j: Integer;
begin
//showmessage('1');
{ if Sender is TfrCrossView then
begin
Cross := TfrxCrossView(Sender);
for i := 1 to StringGrid1.RowCount -1 do
for j := 1 to StringGrid1.ColCount -1 do
Cross.AddValue([i], [j], [StringGrid1.Cells[i - 1, j - 1]]);
end; }
end;
procedure TForm1.frReport1GetValue(const ParName: String;
var ParValue: Variant);
begin
if AnsiCompareText(ParName, 'Cell1') = 0 then
ParValue := StringGrid1.Cells[0, Dataset.RecNo]
else if AnsiCompareText(ParName, 'Cell2') = 0 then
ParValue := StringGrid1.Cells[1, Dataset.RecNo]
else if AnsiCompareText(ParName, 'Cell3') = 0 then
ParValue := StringGrid1.Cells[2, Dataset.RecNo]
else if AnsiCompareText(ParName, 'Cell4') = 0 then
ParValue := StringGrid1.Cells[3, Dataset.RecNo]
else if AnsiCompareText(ParName, 'Cell5') = 0 then
ParValue := StringGrid1.Cells[4, Dataset.RecNo]
end;procedure TForm1.Button1Click(Sender: TObject);
begin
self.frReport1.ShowReport;
end;procedure TForm1.DatasetCheckEOF(Sender: TObject; var Eof: Boolean);
begin
Eof := Dataset.RecNo >= StringGrid1.RowCount;
end;end.
var
i:integer;
j:integer;
begin
for i:=1 to StringGrid1.RowCount -1 do
for j:=1 to StringGrid1.ColCount -1 do
StringGrid1.Cells[i,j]:=IntToStr(i*j);
end; procedure TForm1.BitBtn1Click(Sender: TObject);
begin
frxReport1.ShowReport ;
end; 程序里写好,打印时直接调用即可
根本不需要用fastreport。
那需要用什么?能不能详细点?
try__again :如果只想打印stringgrid的内容,不必要用crosstab,用一个dateset就可以了 。
呵呵,朋友,我对delphi不熟,请问一下dateset是否可以在不链接数据库,不执行sQL的情况下用代码设置其字段和记录值?我尝试了几次均失败,不知道是我做的不对还是本来就不行。