Use Rave with MyDac

507 views Asked by At

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.

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.

2

There are 2 answers

0
Kevin G. McCoy On

I only know how to do this in Delphi, so you will have to translate it to CBuilder equivalents. I am pretty sure that Delphi and CBuilder are identical with respect to RAVE components. I don't know how to do this programmatically, but it is relatively easy using the RAVE report designer.

I use RAVE TRvDataSetConnection components to link TMyQuery components to reports.

You typically drop TRvDataSetConnection components on your datamodule, along with your queries - one TRvDataSetConnection per TMyQuery. You have to add all the SQL fields to your TMyQuery components to make the field names show up in the report designer. You can do this automatically by opening the Field Editor for a TMyQuery and hitting ^F. If you have a valid connection to your MySQL server then the fields will fill in and be assigned the proper data types.

Next, inside the RAVE report designer you create a New Data Object and select the Direct Data View item. Connect the DataView to the RvDataSetConnections in your datamodule. Now you can access all the fields to the TMyQuery. You link the DataView in the RAVE Designer to the report band you want to display the query contents in.

Plan B is to buy and install FastReports. RAVE is pretty bad :-)

0
enzo1959 On

MY own way to use Rave as generic print utility

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

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 )

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 )

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