关于fastreport,给两个memo赋值就出错(100分)

  • 主题发起人 主题发起人 ifall
  • 开始时间 开始时间
I

ifall

Unregistered / Unconfirmed
GUEST, unregistred user!
如:
procedure TForm1.frxReport1BeforePrint(c: TfrxReportComponent);
var
t,p:tfrxmemoview;
begin
if c.name='Memo1' then
begin
t.memo.Text := 'FastReport1';
end;

if c.name='Memo2' then
begin
p.memo.Text := 'FastReport2';
end;
end;

这样就会出错,但如果去掉两个中间的任一句为memo赋值的语句,就正常了~~why??
 
你没有给t和p付值
如下
var
t,p:tfrxmemoview;
begin
if Sender.name='Memo1' then
begin
t := tfrxmemoview(Sender);
t.memo.Text := 'FastReport1';
end;

if Sender.name='Memo2' then
begin
p := tfrxmemoview(Sender);
p.memo.Text := 'FastReport2';
//tfrxmemoview(Sender)
end;

正规应该是这样的
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, frxClass, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
frxReport1: TfrxReport;
procedure Button1Click(Sender: TObject);
procedure frxReport1BeforePrint(Sender: TfrxReportComponent);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
frxReport1.LoadFromFile('e:/2.fr3');
frxReport1.ShowReport;
end;

procedure TForm1.frxReport1BeforePrint(Sender: TfrxReportComponent);
begin
if Sender.name='Memo1' then
begin
tfrxmemoview(Sender).memo.Text := 'FastReport1';
end;

if Sender.name='Memo2' then
begin
tfrxmemoview(Sender).memo.Text := 'FastReport2';
end;
end;

end.
 
多人接受答案了。
 
后退
顶部