2012-10-23 38 views
0

我使用的是Cbuilder XE,我想使用帶有Mydac組件的Rave Report,但在我看來,Rave只能識別標準的TQuery組件並忽略Mydac版本。使用Rave與MyDac

我會問你是否有一種方法來使用TMyQuery組件和可能來提供Rave報告,這是一個簡單的例子,它打印這樣的查詢結果的簡單列表。

回答

1

我只知道如何在Delphi中做到這一點,所以你將不得不把它翻譯成CBuilder等價物。我很確定Delphi和CBuilder與RAVE組件相同。我不知道如何以編程方式執行此操作,但使用RAVE報表設計器相對容易。

我使用RAVE TRvDataSetConnection組件將TMyQuery組件鏈接到報表。

您通常會將TRvDataSetConnection組件放在您的數據模塊上以及您的查詢 - 每個TMyQuery一個TRvDataSetConnection。您必須將所有SQL字段添加到TMyQuery組件中,以使字段名稱顯示在報告設計器中。您可以通過打開TMyQuery的字段編輯器並點擊^ F自動執行此操作。如果你有一個有效的連接到你的MySQL服務器,那麼這些字段將被填入並被分配正確的數據類型。

接下來,在RAVE報表設計器中,創建一個新數據對象並選擇直接數據視圖項目。將DataView連接到數據模塊中的RvDataSetConnections。現在您可以訪問TMyQuery的所有字段。您將RAVE設計器中的DataView鏈接到要顯示查詢內容的報告帶。

B計劃是購買並安裝FastReports。 RAVE是非常糟糕:-)

0

我自己的方式來使用的Rave作爲通用打印實用

void __fastcall TFormMain::Action_ReportExecute(TObject * Sender) 
{ 
    __try 
    { 
     Screen->Cursor = crHourGlass; 
     int maxrow  = 0; 
     RvSystem1->Execute(); 
    } 
    __finally 
    { 
     Screen->Cursor = crDefault; 
    } 
} 

RvSystem1Print:是RvSystem組件 的事件onPrint我不能能夠建立它在運行 - 時間,所以我必須添加的成分爲每個表單,我需要打印實用

void __fastcall TFormMain::RvSystem1Print(TObject * Sender) 
{ 
    int maxrow = 0; 
    String Fun = "[FormMain::RvSystem1Prin] "; 
    try 
    { 
     RvSystem1->SystemPreview->FormWidth = (Screen->Width > 900) ? 900 : Screen->Width ; 
     RvSystem1->SystemPreview->FormHeight = Screen->Height * 0.9; 
     TBaseReport * report     = (TBaseReport*) Sender; 
     UtilClientPmv::DBGridToRaveReport(DBGrid1, report, maxrow); 
    } 
    catch (Exception & ex) 
    { 
     Mylog(Fun + Sysutils::Format("ERROR=[%s] ", ARRAYOFCONST((ex.Message)))); 
    } 
} 

DBGridToRaveReport:掃描並打印在鏈接到一個DBGrid表中的所有記錄(包括圖片)

int __fastcall UtilClientPmv::DBGridToRaveReport(TDBGrid * grid, TBaseReport * report, int maxrow) 
{ 
    String Fun   = "[UtilClientPmv::DBGridToRaveReport] "; 
    TMWTable * mwTable = NULL; 
    int iret   = IRET_OK; 

    try 
    { 
     mwTable = (TMWTable*) grid->DataSource->DataSet; 
     iret = MWTableToRaveReport(mwTable, report, maxrow); 
    } 
    catch (Exception & ex) 
    { 
     Util::mylog(Fun + Sysutils::Format("ERROR=[%s] ", ARRAYOFCONST((ex.Message)))); 
    } 
    return iret; 
} 

MWTableToRaveReport:掃描和打印所有記錄在表格(包括圖片)

int __fastcall UtilClientPmv::MWTableToRaveReport(TMWTable * mwTable, TBaseReport * report, int maxrow) 
{ 
    String fldName, fldValue, smsg, Fun = "[UtilClientPmv::MWTableToRaveReport] "; 
    int tot_row, tot_fld, tot_rec, iret = IRET_OK; 
    double x, y, y2, rpos, pgWidth; 
    TField * fld = NULL; 
    TBookmark bkMark; // TBookmark == TByteDynArray 
    Graphics::TBitmap * bitmap = NULL; 

    try 
    { 
     if (maxrow == 0) 
     { 
      maxrow = 1000; 
     } 

     __try 
     { 
      if (mwTable->Active == false) 
      { 
       mwTable->Active = true; 
      } 
      tot_row = mwTable->Data->RecordCount; 
      if (tot_row < 0) 
      { 
       throw Exception("RecordCount in Null"); 
      } 
      if (tot_row > maxrow) 
      { 
       tot_row = maxrow; 
      } 

      report->StatusFormat = "Page %d"; 
      report->Units = unMM; 
      pgWidth  = report->PageWidth; 

      mwTable->DisableControls(); 
      bkMark = mwTable->GetBookmark(); 

      tot_fld = mwTable->FieldCount; 
      tot_rec = mwTable->RecordCount; 

      int irow = 1, icol; 

      mwTable->First(); 

      report->SetFont("Courier New", 10); 
      report->PrintCenter("Report PmvManager", pgWidth/2); 
      report->NewLine(); 
      report->SetTab(10, pjLeft, 160, 0, 0, 0); 

      while (!mwTable->Eof) 
      { 
       smsg = Sysutils::Format("Record %03d/%03d", ARRAYOFCONST((irow, tot_row))); 
       report->PrintTab(smsg); 
       report->NewLine(); 

       for (int icol = 0; icol < tot_fld; icol++) 
       { 
        String NumberFormat, strValue; 
        fld  = mwTable->Fields->Fields[icol]; 
        fldName = fld->DisplayName; 

        // int lnum = report->LineNum; 
        int lleft = report->LinesLeft(); 
        if (lleft == 0) 
        { 
         report->NewPage(); 
        } 
        if (fld->DataType == ftBlob) 
        { 
         smsg = Sysutils::Format("%30s : ", ARRAYOFCONST((fldName))); 
         report->PrintTab(smsg); 
         x = report->XPos; 
         y = report->YPos; 
         if (!fld->IsNull) 
         { 

          bitmap = new Graphics::TBitmap(); 
          __try 
          { 
           TGraphicField * gFld = (TGraphicField*)fld; 
           if (gFld) 
           { 
            TMemoryStream * memStream = new TMemoryStream(); 
            __try 
            { 
             gFld->SaveToStream(memStream); 
             if (memStream->Size > 1) 
             { 
              memStream->Seek(0, soFromBeginning); 
              bitmap->LoadFromStream(memStream); 
              report->PrintBitmapRect(x, y - 3, x + 12, y + 9, bitmap); 
             } 
             report->NewLine(); 
             report->NewLine(); 
            } 
            __finally 
            { 
             delete memStream; 
             memStream = 0; 
            } 
           } 
          } 
          __finally 
          { 
           delete bitmap; 
           bitmap = 0; 
          } 
         } 
        } 
        else 
        { 
         fldValue = fld->AsString; 
         smsg  = Sysutils::Format("%30s : %s ", ARRAYOFCONST((fldName, fldValue))); 
         report->PrintTab(smsg); 
        } 
        report->NewLine(); 
       } 
       irow++; 
       mwTable->Next(); 

       x = report->XPos; 
       y = report->YPos; 
       report->MoveTo(2, y); 
       report->LineTo(pgWidth - 4, y); 
       report->MoveTo(x, y); 

       report->NewLine(); 
       report->NewPara(); 
      } 
     } 
     __finally 
     { 
      mwTable->GotoBookmark(bkMark); 
      mwTable->EnableControls(); 
      mwTable->FreeBookmark(bkMark); 
     } 

    } 
    catch (Exception & ex) 
    { 
     Util::mylog(Fun + Sysutils::Format("ERROR=[%s] ", ARRAYOFCONST((ex.Message)))); 
    } 
    return iret; 

} // __________ UtilClientPmv::MWTableToRaveReport