I am writing my custom visual component and find it convenient to publish some of its properties as array:
class PACKAGE TVctDiag2 : public TCustomControl
{
__published:
__property int ArrowStyle[int index] = {read=GetArrowStyle,write=SetArrowStyle};
protected:
void __fastcall SetArrowStyle(int index, int value);
int __fastcall GetArrowStyle(int index);
...
};
Component is built and installed without problems. But after I try to insert component on form, access violation message box shows. When debugging source of error I found, that method GetArrowStyle is called with index value of -1 which causes reading out of array bounds. I understand that user of TVctDiag2 class (=integrated development environment) cannot know what is the array size. The size of array is constant and its quite a small number (6), so alternative solution would be:
class PACKAGE TVctDiag2 : public TCustomControl
{
__published:
__property int ArrowStyle1 = {read=GetArrowStyle1,write=SetArrowStyle1};
__property int ArrowStyle2 = {read=GetArrowStyle2,write=SetArrowStyle2};
__property int ArrowStyle3 = {read=GetArrowStyle3,write=SetArrowStyle3};
__property int ArrowStyle4 = {read=GetArrowStyle4,write=SetArrowStyle4};
__property int ArrowStyle5 = {read=GetArrowStyle5,write=SetArrowStyle5};
__property int ArrowStyle6 = {read=GetArrowStyle6,write=SetArrowStyle6};
protected:
void __fastcall SetArrowStyle1(int index, int value);
int __fastcall GetArrowStyle1(int index);
void __fastcall SetArrowStyle2(int index, int value);
int __fastcall GetArrowStyle2(int index);
void __fastcall SetArrowStyle3(int index, int value);
int __fastcall GetArrowStyle3(int index);
void __fastcall SetArrowStyle4(int index, int value);
int __fastcall GetArrowStyle4(int index);
void __fastcall SetArrowStyle5(int index, int value);
int __fastcall GetArrowStyle5(int index);
void __fastcall SetArrowStyle6(int index, int value);
int __fastcall GetArrowStyle6(int index);
...
};
But I prefer more general solution. How can this be accomplished, if possible with option to change property values through Object inspector.