473,320 Members | 2,107 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,320 software developers and data experts.

Self intializaed class

Questing:
Following program. I want on request of property of some class if the class
not initialized - do it, but the following returns exception (...not set to
the instance of the object...) Why?
SomeClass class = GetThisClass.SomeClass();

//Class
class SomeClass
{
public SomeClass()
{}
}

class GetThisClass
{
SomeClass m_class;
public GetThisClass()
{}
public SomeClass SomeClass
{
get
{
if(m_class == null)
m_class=new SomeClass(); //If the class is null
Initialize
return m_class;
}
set
{
m_class = value;
}

}
}

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "

Nov 16 '05 #1
2 1163
The main problem is in the statement
SomeClass class = GetThisClass.SomeClass(); There are 3 problems:
(1) class is a keyword, cannot be used as an identifier.
(2) SomeClass is a property, so () should not be used.
(3) SomeClass is an instance property (not a static one), so it requires an instance of the class GetThisClass.

Replace the above statement with the following one:

SomeClass c = (new GetThisClass()).SomeClass;

It will work fine.
Hope this helps.

--
Sameeksha,
MCP (.NET)
"Tamir Khason" wrote:
Questing:
Following program. I want on request of property of some class if the class
not initialized - do it, but the following returns exception (...not set to
the instance of the object...) Why?
SomeClass class = GetThisClass.SomeClass();

//Class
class SomeClass
{
public SomeClass()
{}
}

class GetThisClass
{
SomeClass m_class;
public GetThisClass()
{}
public SomeClass SomeClass
{
get
{
if(m_class == null)
m_class=new SomeClass(); //If the class is null
Initialize
return m_class;
}
set
{
m_class = value;
}

}
}

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "

Nov 16 '05 #2
Thsnk you for response:
(1) class is a keyword, cannot be used as an identifier. Just for demonstatration (2) SomeClass is a property, so () should not be used. Typo (3) SomeClass is an instance property (not a static one), so it requires an instance of the class GetThisClass.
This was the problem and got it :)

Tnx anyway

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
"Sameeksha" <Sa*******@discussions.microsoft.com> wrote in message
news:6D**********************************@microsof t.com... The main problem is in the statement
SomeClass class = GetThisClass.SomeClass(); There are 3 problems:
(1) class is a keyword, cannot be used as an identifier.
(2) SomeClass is a property, so () should not be used.
(3) SomeClass is an instance property (not a static one), so it requires an instance of the class GetThisClass.
Replace the above statement with the following one:

SomeClass c = (new GetThisClass()).SomeClass;

It will work fine.
Hope this helps.

--
Sameeksha,
MCP (.NET)
"Tamir Khason" wrote:
Questing:
Following program. I want on request of property of some class if the class not initialized - do it, but the following returns exception (...not set to the instance of the object...) Why?
SomeClass class = GetThisClass.SomeClass();

//Class
class SomeClass
{
public SomeClass()
{}
}

class GetThisClass
{
SomeClass m_class;
public GetThisClass()
{}
public SomeClass SomeClass
{
get
{
if(m_class == null)
m_class=new SomeClass(); //If the class is null Initialize
return m_class;
}
set
{
m_class = value;
}

}
}

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "

Nov 16 '05 #3

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

Similar topics

37
by: Grzegorz Staniak | last post by:
Hello, I'm a newbie Python user, a systems administrator - I've been trying to switch from Perl to Python for administrative tasks - and one thing I cannot understand so far is why I need the...
2
by: Jim Jewett | last post by:
Normally, I expect a subclass to act in a manner consistent with its Base classes. In particular, I don't expect to *lose* any functionality, unless that was the whole point of the subclass. ...
2
by: Marc | last post by:
Hi all, I was using Tkinter.IntVar() to store values from a large list of parts that I pulled from a list. This is the code to initialize the instances: def initVariables(self): self.e =...
1
by: Alexander Kervero | last post by:
Hi ,today i was reading diveinto python book,in chapter 5 it has a very generic module to get file information,html,mp3s ,etc. The code of the example is here :...
15
by: Ralf W. Grosse-Kunstleve | last post by:
****************************************************************************** This posting is also available in HTML format: http://cci.lbl.gov/~rwgk/python/adopt_init_args_2005_07_02.html...
20
by: Wayne Sutton | last post by:
OK, I'm a newbie... I'm trying to learn Python & have had fun with it so far. But I'm having trouble following the many code examples with the object "self." Can someone explain this usage in...
4
by: marek.rocki | last post by:
First of all, please don't flame me immediately. I did browse archives and didn't see any solution to my problem. Assume I want to add a method to an object at runtime. Yes, to an object, not a...
7
by: Andrew Robert | last post by:
Hi Everyone, I am having a problem with a class and hope you can help. When I try to use the class listed below, I get the statement that self is not defined. test=TriggerMessage(data) var...
8
by: ssecorp | last post by:
I first learned about OO from Java. I much prefer to program in Python though. However I am consufed about 2 things. 1. Why do I have to pass self into every method in a class? Since I am...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.