Re: Object scope issue...
- From: "Scott M." <smar@xxxxxxxxxxxxx>
- Date: Tue, 5 Feb 2008 18:19:37 -0500
I have a few thoughts on this.
First, you seem to be asking about 2 separate things. The first is your
database issue, which forces me to ask if you are using a DataSet to store
your data. If so, a DataSet is already equipped to keep track of the
changes to the data and the type of changes that were made (add, delete,
modify). This makes knowing what action to perform, based on what was done
to the data a no-brainer.
Second, if you could just show us your code, we could see how your variable
scope is set up.
-Scott
"Brad Pears" <bradp@xxxxxxxxxxxxxxxxxxxxx> wrote in message
news:OMG8tNEaIHA.3940@xxxxxxxxxxxxxxxxxxxxxxx
I just have a question about how objects should be used in situations where
you want to preserve an object's state while performing some particular
function.
In my vb.net 2005 app, a user enters data and then clicks a "Save" command
button to save the row. If the user simply changes existing data on the
form, (meaning a row already exists) I only do a database update. However,
if the user was adding a new row I would have first created a new instance
of the object and subsequently added the row data to the database.
I set up the object as a "public" variable in my main vb module like
this...
"public MyObj as clsMyObj"
Then in the "Save" command button code, I first check to see if MyObj =
nothing. If so, I then create a new instance of the object (MyObj=new
clsMyObj) and run code that inserts the new row.
If the user were to go back and modify some data and clicks the "Save"
command button again, I
would expect my code above (if MyObj = nothing ) to be false and I would
then just update the data as opposed to updating it.
Is this typically how one would control an objects scope - by setting as a
public variable and checking to see if
the object = nothing or object = something? If so than does this mean that
for any object that I need to preserve scope, I need to setup as a
public variable?
I am new to OO design etc... and I want to make sure that I don't have
copies of objects all over the place etc... It seems that there must be a
better way to do this?
Help!
Thanks, Brad
.
- Follow-Ups:
- Re: Object scope issue...
- From: Brad Pears
- Re: Object scope issue...
- References:
- Object scope issue...
- From: Brad Pears
- Object scope issue...
- Prev by Date: double-click file & open in existing instance of an application
- Next by Date: Re: Instance object directly to disk not to memory
- Previous by thread: Object scope issue...
- Next by thread: Re: Object scope issue...
- Index(es):
Loading