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

Calling Constructor from within the class.

Is it possible to call an objects constructor method from within the class
somehow? The class I have populates itself with data from a sqlServer
database when it is constructed, and I want to expose a method like
"refresh" which, essentially just "remakes" the object. However I can't do:

this = new ProjectCollection();

but "this" is read-only. Can an object modify itself in this way?

-D
Nov 15 '05 #1
3 7503
Just pull all of the code that "hydrates" your class out of the constructor
into it's own method. Then call that method from the constructor and
anywhere you want to "refresh" the class.

Jeff Woodie

"MC D" <as***@earthtalk.com> wrote in message
news:eu*************@TK2MSFTNGP10.phx.gbl...
Is it possible to call an objects constructor method from within the class
somehow? The class I have populates itself with data from a sqlServer
database when it is constructed, and I want to expose a method like
"refresh" which, essentially just "remakes" the object. However I can't do:
this = new ProjectCollection();

but "this" is read-only. Can an object modify itself in this way?

-D

Nov 15 '05 #2
Ummm...maybe I am missing the point but why don't you just Make a method
that reloads the data. You can then call that method from the constructor.
Maybe I am missing something but it would look like this....

class Foo
{
public Foo()
{
Refresh();
}
public void Refresh()
{
//load data into object.
}
}
"MC D" <as***@earthtalk.com> wrote in message
news:eu*************@TK2MSFTNGP10.phx.gbl...
Is it possible to call an objects constructor method from within the class
somehow? The class I have populates itself with data from a sqlServer
database when it is constructed, and I want to expose a method like
"refresh" which, essentially just "remakes" the object. However I can't do:
this = new ProjectCollection();

but "this" is read-only. Can an object modify itself in this way?

-D

Nov 15 '05 #3
Yes, I could do that. I guess my question was more theoretical. Why can't
an object do that to itself?

-D
"Jeff Woodie" <jw*****@taxcomp.com> wrote in message
news:Of**************@TK2MSFTNGP10.phx.gbl...
Just pull all of the code that "hydrates" your class out of the constructor into it's own method. Then call that method from the constructor and
anywhere you want to "refresh" the class.

Jeff Woodie

"MC D" <as***@earthtalk.com> wrote in message
news:eu*************@TK2MSFTNGP10.phx.gbl...
Is it possible to call an objects constructor method from within the class somehow? The class I have populates itself with data from a sqlServer
database when it is constructed, and I want to expose a method like
"refresh" which, essentially just "remakes" the object. However I can't

do:

this = new ProjectCollection();

but "this" is read-only. Can an object modify itself in this way?

-D


Nov 15 '05 #4

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

Similar topics

4
by: Murat Tasan | last post by:
i have a quick question... is there a way to obtain the reference to the object which called the currently executing method? here is the scenario, i have a class and a field which i would like to...
3
by: Brett Irving | last post by:
Hi once again, another question, I want to make a class object MyArray a global but have no idea about how to go about initialising it within the constructor as it wont let me do something like,...
5
by: Bennett Haselton | last post by:
I've noticed that if you enter the following code in the codebehind page for an .aspx page, it won't compile because the call to Trace.Write() is not valid except in methods of a class derived from...
1
by: JezB | last post by:
In my Page_Load event of all my web app Pages and UserControls I instantiate the same library class "TextResources" (to take care of reading presentation text strings from localizable resource...
7
by: John | last post by:
Hi I have two distinct classes A & B. I am using class B from within Class A as follows; Public Class clsClassA Friend ClassB As new ClassB Public Sub New()
12
by: st_ev_fe | last post by:
I've noticed that when constructing a subclass, the base class get's it's contructors called. Is there some way to avoid this? The base class has one variable, which gets initialised to 0. ...
4
by: Michael | last post by:
Hello, I want to use an object (LowCut) within another object (SampleRateConverter) like it is written as follows: class SampleRateConverter { public: SampleRateConverter( int...
4
by: Fedor Semenov | last post by:
How can I call a base class' constructor from a derived class. Suppose I have: class Button // Base class { public: Button(void) { // Register classes, create the button, etc. } };
7
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
I have a C# logging assembly with a static constructor and methods that is called from another C# Assembly that is used as a COM interface for a VB6 Application. Ideally I need to build a file...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.