user1690531
user1690531

Reputation: 241

BoldDays with TMonthCalendar

I have written a C++ Builder VCL Forms application with a TMonthCalendar control called TMonthCalendar.

I am wanting to set some of the days with the control to be bold.

Here is my current code:

TMonthCalendar->BoldDays([1,8], MonthBoldInfo);

However I am getting the following error:

E2193 Too few parameters in call to '_fastcall TCommonCalendar::BoldDays(unsigned int *,const int,unsigned int &)'

Can I please have some help to do this?

Here is a link to the documentation: http://docwiki.embarcadero.com/Libraries/XE3/en/Vcl.ComCtrls.TMonthCalendar.OnGetMonthInfo

I see no difference between my code and the documentation. Yet I still get errors.

thanks

UPDATE

I am trying the following code:

unsigned int arr[2] = {1,8};
TMonthCalendar->BoldDays(arr, 1, MonthBoldInfo);

Yet am getting the following errors:

[BCC32 Error] Assessment2.cpp(361): E2357 Reference initialized with 'unsigned long', needs lvalue of type 'unsigned int' Full parser context Assessment2.cpp(359): parsing: void _fastcall TformMain::TMonthCalendarGetMonthInfo(TObject *,unsigned long,unsigned long &)

and

[BCC32 Error] Assessment2.cpp(361): E2342 Type mismatch in parameter 'MonthBoldInfo' (wanted 'unsigned int &', got 'unsigned long') Full parser context Assessment2.cpp(359): parsing: void _fastcall TformMain::TMonthCalendarGetMonthInfo(TObject *,unsigned long,unsigned long &)

UPDATE

I am wanting to retrieve all the days of a certain month from a vector and then set the days to bold via the TMonthCalendar control.

Here is my code:

vector<appointment> appointmentsOnMonth = calCalendar.getAllAppointmentsOnMonth(TMonthCalendar->Date);
if (appointmentsOnMonth.size() > 0)
{
    unsigned int arr[appointmentsOnMonth.size()];
    for (int i = 0; i < appointmentsOnMonth.size(); i++)
    {
        int dayOfAppointment = DayOf(appointmentsOnMonth[i].getAppDateTime());
        arr[i] = dayOfAppointment;
    }
    TMonthCalendar->BoldDays(arr, 1, reinterpret_cast<unsigned int&>(MonthBoldInfo));
}

The dayOfAppointment variable is working correctly and gets the value as an integer of the days that should be displayed in bold. I am after some help to please display these days as bold days.

I am getting some errors to do with the unsigned int arr[] and displaying the bold days. Here they are:

[BCC32 Error] Assessment2.cpp(366): E2313 Constant expression required [BCC32 Error] Assessment2.cpp(372): E2034 Cannot convert 'int[1]' to 'unsigned int *'

I think this is because the static array requires compile time constants and thus the second code will never compile. Is there a way around this?

Upvotes: 1

Views: 1211

Answers (1)

Remy Lebeau
Remy Lebeau

Reputation: 595971

The first two parameters of BoldDays() in C++ consist of a single open array parameter in Delphi. An open array consists of a data pointer and a max index into the data being pointed at. In C++, you cannot use the [1,8] syntax. That is Delphi syntax instead. In C++, use the ARRAYOFCONST() or OPENARRAY() macro instead, eg:

TMonthCalendar->BoldDays(ARRAYOFCONST((1,8)), MonthBoldInfo);

Or:

TMonthCalendar->BoldDays(OPENARRAY(unsigned int, (1,8)), MonthBoldInfo);

Or, just declare the parameter values manually using your own array:

unsigned int arr[2] = {1,8};
TMonthCalendar->BoldDays(arr, 1, MonthBoldInfo);

Update: The MonthBoldInfo parameter of the OnGetMonthInfo event is an unsigned long&, but BoldDays() takes an unsigned int& instead. When passing values by reference, the data types need to match. You have two choices:

1) use an intermediate variable:

unsigned int arr[2] = {1,8};
unsigned int days;
TMonthCalendar->BoldDays(arr, 1, days);
MonthBoldInfo = days;

2) use a typecast:

unsigned int arr[2] = {1,8};
TMonthCalendar->BoldDays(arr, 1, reinterpret_cast<unsigned int&>(MonthBoldInfo));

Update: you cannot declare a static fixed-length array using a run-time value. You have to use a dynamically allocated array instead. Since you are already using std::vector, you can use that for the array:

vector<appointment> appts = calCalendar.getAllAppointmentsOnMonth(TMonthCalendar->Date);
if (!appts.empty())
{
    vector<unsigned int> arr(appts.size());
    for (vector<appointment>::iterator i = appts.begin(); i != appts.end(); ++i)
    {
        arr[i] = DayOf(i->getAppDateTime());
    }
    TMonthCalendar->BoldDays(&arr[0], arr.size()-1, reinterpret_cast<unsigned int&>(MonthBoldInfo));
}

With that said, the OnGetMonthInfo event is meant for retrieving the bold days for a given month in all years, ie recurring events, so it doesn't make sense to use the TMonthCalendar::Date property like you are. You are supposed to use the provided Month parameter instead:

vector<appointment> appts = calCalendar.getAllAppointmentsOnMonth(Month);

To set the bold days for a given month of a specific year, use the OnGetMonthBoldInfo event instead, which provides you Month and Year parameters:

vector<appointment> appts = calCalendar.getAllAppointmentsOnMonthOfYear(Month, Year);

Upvotes: 3

Related Questions