1

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?

4

1 回答 1

3

C++ 中的前两个参数BoldDays()由 Delphi 中的一个开放数组参数组成。开放数组由数据指针和指向数据的最大索引组成。在 C++ 中,您不能使用[1,8]语法。那是 Delphi 语法。在 C++ 中,请改用ARRAYOFCONST()orOPENARRAY()宏,例如:

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

或者:

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

或者,只需使用您自己的数组手动声明参数值:

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

更新:事件的MonthBoldInfo参数OnGetMonthInfo是一个unsigned long&,但取而代之的是BoldDays()一个。unsigned int&通过引用传递值时,数据类型需要匹配。你有两个选择:

1)使用中间变量:

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

2)使用类型转换:

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

更新:您不能使用运行时值声明静态固定长度数组。您必须改用动态分配的数组。由于您已经在使用std::vector,因此可以将其用于数组:

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));
}

话虽如此,该OnGetMonthInfo事件旨在检索所有年份中给定月份的粗体天数,即重复事件,因此TMonthCalendar::Date像您一样使用该属性是没有意义的。您应该改用提供的Month参数:

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

要为特定年份的给定月份设置粗体日期,请改用OnGetMonthBoldInfo事件,它提供您MonthYear参数:

vector<appointment> appts = calCalendar.getAllAppointmentsOnMonthOfYear(Month, Year);
于 2012-10-10T19:30:51.300 回答