473,395 Members | 1,383 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Image as property

Hi,

I'm creating my own .NET control and i would like to allow user to
allocate an image as property.

for that i used the following 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")]
property Image^ ImageSortAscendant
{
Image^ get()
{
return m_ImageSortA;
}
void set(Image^ value)
{
if(value->Height == 8 && value->Width == 8)
{
m_ImageSortA = value;
}
}
}
#pragma endregion

However, i have a stupid runtime error.
"An unhandled exception of type 'System.NullReferenceException' occurred
in System.Drawing.dll
Additional information: Object reference not set to an instance of an
object."

so i do not have any instance of my object...but about which object ?
because this error occurs on line == if(value->Height == 8 &&
value->Width == 8)

therefore i suppose that it is relative to value object which is not
instanciated as Image ^value = gcnew Image();

however, i've never seen in any book instanciation for such thing at
this stage of component.

please, could you tell me what to do ?
thx.

Al.
Oct 21 '06 #1
3 1318
Hi Alain,

"--== Alain ==--" <no****@noemail.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
Hi,

I'm creating my own .NET control and i would like to allow user to
allocate an image as property.

for that i used the following 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")]
property Image^ ImageSortAscendant
{
Image^ get()
{
return m_ImageSortA;
}
void set(Image^ value)
{
Check if value is nullptr before using it.
if(value->Height == 8 && value->Width == 8)
{
m_ImageSortA = value;
}
}
}
#pragma endregion

However, i have a stupid runtime error.
"An unhandled exception of type 'System.NullReferenceException' occurred
in System.Drawing.dll
Additional information: Object reference not set to an instance of an
object."

so i do not have any instance of my object...but about which object ?
because this error occurs on line == if(value->Height == 8 &&
value->Width == 8)
Are you sure about where the exception occurs?
If yes, of what type is value?

Do you own the code which uses your control? How do you set the property?

--
SvenC
therefore i suppose that it is relative to value object which is not
instanciated as Image ^value = gcnew Image();

however, i've never seen in any book instanciation for such thing at this
stage of component.

please, could you tell me what to do ?
thx.

Al.

Oct 21 '06 #2
Hi Sven,
Check if value is nullptr before using it.
Yes i set it to nullptr in component constructor to initialize it.
Are you sure about where the exception occurs?
If yes, of what type is value?
value is the same type as property. it means Image^ but as for value,
undefined..
I solved it by writting m_ImageSortA = value; before to make all tests
on it.

but if i do that, i can not have null value for this property once it
has been set :-(

Do you own the code which uses your control? How do you set the property?
yes, as i'm the component creator ;-)
Oct 21 '06 #3
Hi Alain,

"--== Alain ==--" <no****@noemail.comwrote in message
news:eT**************@TK2MSFTNGP04.phx.gbl...
Hi Sven,
>Check if value is nullptr before using it.
Yes i set it to nullptr in component constructor to initialize it.
>Are you sure about where the exception occurs?
If yes, of what type is value?
value is the same type as property. it means Image^ but as for value,
undefined..
I was wondering if some derived class was passed in which might produce
problems in your case.
I solved it by writting m_ImageSortA = value; before to make all tests on
it.
Hmm, sounds strange. Why should using value throw and using m_ImageSortA
which got value assigned not throw? Do you have other threads which might
try to access m_ImageSortA while it is still nullptr?
but if i do that, i can not have null value for this property once it has
been set :-(
Why not? Just check m_ImageSortA != nullptr before you use it to check its
properties. Did I missunderstand that?
>Do you own the code which uses your control? How do you set the property?
yes, as i'm the component creator ;-)
I understood that you are the component creator but do you also write the
code which uses your component? What values are assigned to
ImageSortAscendant? Might the component user cause the exception by using
the component in an unexpected way?

--
SvenC
Oct 22 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Ed Landau | last post by:
In VB6.0, I can put an image on a form and assign it's .picture property at run-time. In VBA (within MS Access), when I put down an image control on a form, it asks me for the source to the image...
8
by: iyuen | last post by:
I'm having problems with converting a byte array to an image object~ My byte array is an picture in VB6 StdPicture format. I've used propertybag to convert the picture into base64Array format in...
7
by: Scott Schluer | last post by:
Is there a way to use the Image class to convert a color photo (GIF or JPEG) to a B&W photo? Thanks, Scott
6
by: anonymous | last post by:
hi all, I'm trying to use the capCreateCaptureWindow (see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/htm/_win32_capcreatecapturewindow.asp) in a Windows...
4
by: NASAdude | last post by:
I'm working on distributing a database using VS Tools for Office, and am having trouble with linked images on forms/reports. The image objects have a default path\file set on the .Picture property,...
2
by: Marc Solé | last post by:
Hello, I want to insert an image to a specific column of a dataGridWiew. I explain what I'm doing: - I define the ColumnType as a DataGridViewImageColumn. - I select the image (an icon of...
9
by: Eric | last post by:
Hi Everyone, I'm writing a UserControl that exposes a property of the type System.Drawing.Image, like this: Public Property DefaultImage() As Image Get Return propDefaultImage End Get...
0
by: doubts | last post by:
Hi, I have a query regarding reading Image Property for button from a XML file . I read XML files to Generate Screens using System.Windows.Forms.Controls .The XML file is read and properties...
1
by: doubts | last post by:
Hi, I have a query regarding reading Image Property for button from a XML file . I read XML files to Generate Screens using System.Windows.Forms.Controls .The XML file is read and properties...
3
by: Froefel | last post by:
Hi group, I'm looking for some help on how to achieve the following in a gridview control that is based on an ObjectDataSource. The SelectMethod of the datasource returns a list of Customer...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.