"none" for a property

A

--== Alain ==--

Hi,

I've seen that on all component it is possible to have (none) as value
for a property.
Usually i see it for Image or ImageList property type.

So tried it on my component. I can set the image without problem, but i
can not clear the property if i do not want to use it...
to clean the property, i mean by that, to not allocate an image data to
it... so it should display (none) as value.

what could be the problem ?

here is my part of code :
#pragma region public Property : ImageSortAscendant
// Allow user to select the image which will be displayed for column
sorted ascendantly
[Description("Set image (8x8) to represent ascending sorting which will
appear onto sorted column header")]
[CategoryAttribute("Appearance")]
[DefaultValue(nullptr)]
property Image^ ImageSortAscendant
{
Image^ get()
{
return m_ImageSortA;
}
void set(System::Drawing::Image^ value)
{
m_ImageSortA = value;
if(m_ImageSortA->Height != 8 || m_ImageSortA->Width != 8)
{
MessageBox::Show(L"Image should be a 8 x 8 pixels", L"Incorrect
Image Size...",MessageBoxButtons::OK,MessageBoxIcon::Error);
m_ImageSortA = nullptr;
}
}
}
#pragma endregion
//----------------------
thx.
Al.
 
J

Jon Skeet [C# MVP]

--== Alain ==-- said:
I've seen that on all component it is possible to have (none) as value
for a property.
Usually i see it for Image or ImageList property type.

So tried it on my component. I can set the image without problem, but i
can not clear the property if i do not want to use it...
to clean the property, i mean by that, to not allocate an image data to
it... so it should display (none) as value.

what could be the problem ?

When you do:
m_ImageSortA = value;
if(m_ImageSortA->Height != 8 || m_ImageSortA->Width != 8)

it's dereferencing the null reference you've passed in. You need to
check for nullity instead, doing whatever you need to do if null has
been passed in.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top