Report Control Sample----Virtual List虚拟报表的应用

AfxWinMain()

1 CWinThread* pThread = AfxGetThread();  //获得当前运行的线程
2 CWinApp* pApp = AfxGetApp();       //获得CWinApp的唯一对象CVirtualListApp类
3 pThread->InitInstance();            //调用CVirtualListApp类的初始化InitInstance()
4 nReturnCode = pThread->Run();          //运行实例对象

CVirtualListApp()

 //::InitInstance()中实现Doc/Frame/View对象的创建与运行
1 CSingleDocTemplate* pDocTemplate;
2 pDocTemplate = new CSingleDocTemplate(IDR_MAINFRAME,RUNTIME_CLASS(CVirtualListDoc),RUNTIME_CLASS(CMainFrame),
3 RUNTIME_CLASS(CVirtualListView)); //Frame承载View,Document为View中的数据提供管理
4 AddDocTemplate(pDocTemplate);
 5 // Parse command line for standard shell commands, DDE, file open
 6 CCommandLineInfo cmdInfo;
 7 ParseCommandLine(cmdInfo);
 8 // Dispatch commands specified on the command line
 9 if (!ProcessShellCommand(cmdInfo))  //创建并运行Doc/Frame/View实例对象
10  return FALSE;

CVirtualListView()

1 CXTPReportControl& wndReport = GetReportCtrl();  //创建报表控制对象
2 wndReport.AddColumn(new CXTPReportColumn(0, _T("Column 1"), 50)); //报表对象中加入列
3 wndReport.SetVirtualMode(new CVirtualRecord(), 1000000); //设置报表为虚模式下的数据显示,会调用GetItemMetrics()来添加数据
4 wndReport.Populate();

 CVirtualRecord()

 //class CVirtualRecord : public CXTPReportRecord自定义虚拟报表类
1 CVirtualRecord() 2 { 3 AddItem(new CXTPReportRecordItem()); 4 AddItem(new CXTPReportRecordItem()); 5 AddItem(new CXTPReportRecordItem()); 6 } 7 8 void GetItemMetrics (XTP_REPORTRECORDITEM_DRAWARGS* pDrawArgs, XTP_REPORTRECORDITEM_METRICS* pItemMetrics) 9 { // pDrawArgs
     // Pointer to the provided draw arguments structure for calculating metrics
     // G
et the position for each column and row
     
// pItemMetrics
     // Set the data for each column and row
     //例如:
     CString strColumn = pDrawArgs->pColumn->GetCaption(); //获取所在列的标题
     int RowIndex = pDrawArgs->pRow->GetIndex(); //获取行号
     int ColumnIndex = pDrawArgs->pColumn->GetItemIndex(); //获取列号
    pItemMetrics->strText =
GetItemCaption(RowIndex,ColumnIndex); //自定义GetItemCaption()用来获得数据,将数据添加到虚拟报表中
}

1. In regular (non-virtual) mode, Report Control stores data (Records and Record Items) in its internal collection.
2. In virtual mode, Report Control does not store data (except the only one single record to know the data structure). It only needs to store records count and portion of data which is necessary to display.

This is useful if you already have a data storage (a collection of objects or even a DataBase). In this mode data is not duplicated in your storage and Report's storage and you do not need to synchronize both data collections.

 

 

posted on 2012-11-27 15:16  Offen_Lou  阅读(613)  评论(0)    收藏  举报

导航