Cross Tab Object problems
MrWD
Calgary AB, Canada
I looked at the SringGrid example and used it as a template. I made a frxReport and created a Master Data band and the placed a frxCrossView object in it. It assigned 'Cross1' as the object name. I then created a procedure named rptAlertPopulate which is supposed to add the values inti Cross1. Try as I may I cannot get the data to print. Here is the code. Hoping someone can put me in the right direction. BTW I did try to use the rptAlertBeforePrint event approach and still no luck.
Thx
unit frmMainU;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, JvComponentBase, JvMail, IdBaseComponent, IdComponent,
IdTCPConnection, IdTCPClient, IdExplicitTLSClientServerBase, IdMessageClient,
IdPOP3, IdSMTPBase, IdSMTP, LMDCustomScrollBox, LMDListBox, LMDCustomButton,
LMDButton, IdMessage, LMDControl, LMDCustomControl, LMDCustomPanel,IDAttachmentFile,
LMDCustomBevelPanel, LMDCustomStatusBar, LMDStatusBar,IdText,IdGlobal,IdSync,
ComCtrls, Buttons, ExtCtrls, frxClass, frxPrinter, frxCross;
type
TfrmMain = class(TForm)
SalesOrdersPOP3: TIdPOP3;
IdSMTP1: TIdSMTP;
mess: TIdMessage;
list: TListView;
Timer1: TTimer;
BitBtn1: TBitBtn;
Label1: TLabel;
rptAlert: TfrxReport;
frxCrossObject1: TfrxCrossObject;
procedure Timer1Timer(Sender: TObject);
procedure rptAlertPopulate;
private
{ Private declarations }
public
{ Public declarations }
Msgcount:Integer;
li:TListItem;
end;
var
frmMain: TfrmMain;
implementation
{$R *.dfm}
procedure TfrmMain.rptAlertPopulate;
var
Cross: TfrxCrossView;
vRow: Integer;
begin
Cross := TfrxCrossView(rptAlert.FindObject('Cross1'));
for vRow := 0 to list.Items.Count - 1 do
begin
Cross.AddValue([vRow + 1],,[list.Items[vRow].Caption]);
Cross.AddValue([vRow + 1],,[list.Items[vRow].SubItems[0]]);
Cross.AddValue([vRow + 1],,[list.Items[vRow].SubItems[1]]);
end;
end;
procedure TfrmMain.Timer1Timer(Sender: TObject);
var
intindex:Integer;
begin
try
if not SalesOrdersPOP3.Connected then
SalesOrdersPOP3.Connect;
except
showmessage('Could not connect to pop server, please check your connection details');
exit;
end;
msgcount:=SalesOrdersPOP3.CheckMessages;
if msgcount > 0 then
begin
SalesOrdersPOP3.RetrieveHeader(msgcount,mess);
list.Items.Clear;
for intindex:= 1 to msgcount do
begin
Application.ProcessMessages;
Mess.Clear;
SalesOrdersPOP3.RetrieveHeader(intIndex, Mess);
li:=list.Items.Add;
li.ImageIndex := 4;
li.Caption:= mess.From.text;
li.SubItems.add(formatdatetime('dd/mm/yyy hh:mm:ss',mess.Date));
li.SubItems.Add(mess.Subject);
end;
rptAlertPopulate;
rptAlert.printoptions.showdialog := false;
rptAlert.PrintOptions.Printer := 'EPSON WorkForce 610 Series';
rptAlert.showreport;
end;
SalesOrdersPOP3.Disconnect;
end;
end.
Thx
unit frmMainU;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, JvComponentBase, JvMail, IdBaseComponent, IdComponent,
IdTCPConnection, IdTCPClient, IdExplicitTLSClientServerBase, IdMessageClient,
IdPOP3, IdSMTPBase, IdSMTP, LMDCustomScrollBox, LMDListBox, LMDCustomButton,
LMDButton, IdMessage, LMDControl, LMDCustomControl, LMDCustomPanel,IDAttachmentFile,
LMDCustomBevelPanel, LMDCustomStatusBar, LMDStatusBar,IdText,IdGlobal,IdSync,
ComCtrls, Buttons, ExtCtrls, frxClass, frxPrinter, frxCross;
type
TfrmMain = class(TForm)
SalesOrdersPOP3: TIdPOP3;
IdSMTP1: TIdSMTP;
mess: TIdMessage;
list: TListView;
Timer1: TTimer;
BitBtn1: TBitBtn;
Label1: TLabel;
rptAlert: TfrxReport;
frxCrossObject1: TfrxCrossObject;
procedure Timer1Timer(Sender: TObject);
procedure rptAlertPopulate;
private
{ Private declarations }
public
{ Public declarations }
Msgcount:Integer;
li:TListItem;
end;
var
frmMain: TfrmMain;
implementation
{$R *.dfm}
procedure TfrmMain.rptAlertPopulate;
var
Cross: TfrxCrossView;
vRow: Integer;
begin
Cross := TfrxCrossView(rptAlert.FindObject('Cross1'));
for vRow := 0 to list.Items.Count - 1 do
begin
Cross.AddValue([vRow + 1],,[list.Items[vRow].Caption]);
Cross.AddValue([vRow + 1],,[list.Items[vRow].SubItems[0]]);
Cross.AddValue([vRow + 1],,[list.Items[vRow].SubItems[1]]);
end;
end;
procedure TfrmMain.Timer1Timer(Sender: TObject);
var
intindex:Integer;
begin
try
if not SalesOrdersPOP3.Connected then
SalesOrdersPOP3.Connect;
except
showmessage('Could not connect to pop server, please check your connection details');
exit;
end;
msgcount:=SalesOrdersPOP3.CheckMessages;
if msgcount > 0 then
begin
SalesOrdersPOP3.RetrieveHeader(msgcount,mess);
list.Items.Clear;
for intindex:= 1 to msgcount do
begin
Application.ProcessMessages;
Mess.Clear;
SalesOrdersPOP3.RetrieveHeader(intIndex, Mess);
li:=list.Items.Add;
li.ImageIndex := 4;
li.Caption:= mess.From.text;
li.SubItems.add(formatdatetime('dd/mm/yyy hh:mm:ss',mess.Date));
li.SubItems.Add(mess.Subject);
end;
rptAlertPopulate;
rptAlert.printoptions.showdialog := false;
rptAlert.PrintOptions.Printer := 'EPSON WorkForce 610 Series';
rptAlert.showreport;
end;
SalesOrdersPOP3.Disconnect;
end;
end.
Comments
change this line
Cross := TfrxCrossView(rptAlert.FindObject('Cross1'));
to
Cross := rptAlert.FindObject('Cross1') as tfrxcrossview; // find and cast to type
now you can add values using the add value method.
You must use the onbeforeprint event of the tfrxreport component to populate the crossmatrix.
also make sure that in the report you have set up the crossview using its editor.