简体   繁体   English

与MyDac一起使用Rave

[英]Use Rave with MyDac

I'm using Cbuilder XE and I want to use Rave Report with Mydac component but it seems to me that Rave recognize only the standard TQuery component and ignore the Mydac versions. 我正在使用Cbuilder XE,并且希望将Rave Report与Mydac组件一起使用,但在我看来Rave仅识别标准TQuery组件,而忽略Mydac版本。

I would ask you if there is a way to feed a Rave report using TMyQuery component and possiby, a simple example which print a plain list of the result of such query. 我想问您是否有一种方法可以使用TMyQuery组件和possiby来提供Rave报告,这是一个简单的示例,可以打印出这种查询结果的简单列表。

I only know how to do this in Delphi, so you will have to translate it to CBuilder equivalents. 我只知道如何在Delphi中执行此操作,因此您必须将其转换为CBuilder等效项。 I am pretty sure that Delphi and CBuilder are identical with respect to RAVE components. 我很确定Delphi和CBuilder在RAVE组件方面是相同的。 I don't know how to do this programmatically, but it is relatively easy using the RAVE report designer. 我不知道如何以编程方式执行此操作,但是使用RAVE报告设计器相对容易。

I use RAVE TRvDataSetConnection components to link TMyQuery components to reports. 我使用RAVE TRvDataSetConnection组件将TMyQuery组件链接到报表。

You typically drop TRvDataSetConnection components on your datamodule, along with your queries - one TRvDataSetConnection per TMyQuery. 通常,将TRvDataSetConnection组件与查询一起放在数据模块上-每个TMyQuery一个TRvDataSetConnection。 You have to add all the SQL fields to your TMyQuery components to make the field names show up in the report designer. 您必须将所有SQL字段添加到TMyQuery组件中,以使字段名称显示在报表设计器中。 You can do this automatically by opening the Field Editor for a TMyQuery and hitting ^F. 您可以通过打开TMyQuery的字段编辑器并单击^ F来自动执行此操作。 If you have a valid connection to your MySQL server then the fields will fill in and be assigned the proper data types. 如果您与MySQL服务器的连接有效,则将填写字段并为其分配适当的数据类型。

Next, inside the RAVE report designer you create a New Data Object and select the Direct Data View item. 接下来,在RAVE报表设计器中,创建一个新数据对象,然后选择直接数据视图项。 Connect the DataView to the RvDataSetConnections in your datamodule. 将DataView连接到数据模块中的RvDataSetConnections。 Now you can access all the fields to the TMyQuery. 现在,您可以访问TMyQuery的所有字段。 You link the DataView in the RAVE Designer to the report band you want to display the query contents in. 您将RAVE设计器中的DataView链接到要在其中显示查询内容的报告范围。

Plan B is to buy and install FastReports. 计划B是购买和安装FastReports。 RAVE is pretty bad :-) RAVE非常糟糕:-)

MY own way to use Rave as generic print utility 我自己的使用Rave作为通用打印实用程序的方式

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

RvSystem1Print : is the event onPrint of a RvSystem component I can't be able to build it at run-time so I have to add a component for each form where I need the print utility 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: scan and print all record in a table linked to a dbgrid ( included images ) 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: scan and print all record in a table ( included images ) 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM