Overwriting objects does not work

hog

Senior Contributor
Joined
Mar 17, 2003
Messages
984
Location
UK
I have an object which has two contructors, one which requires a parameter and one which does not. I call the parameter contructor first and following recordcount and internal error checking if the object contains no data I call the unparameterised constructor. Problem is although my forms text changed events all appear assign data to my new instance they are infact going to the original.

ie

m_objJob = new job(customerid)

yadda yadda

m_objJob = nothing

m_objJob = new job()

the line assiging nothing was an attempt to get around it, but all I get now is m_objJob not instantiated? Even through I step through the new() contructor code with no error?

Any ideas welcome
 
No, it means that I wrote long elaborations on the use of constructors and the nature of variables / objects.

Until I reread your post and saw, that that was not the problem.

How about this:

Give, for debugging puposes only, your object a readonly property
ObjectGuid = mGUID


Make sure
mGUID = Guid.NewGuid.ToString
is being set in the constructor(s).

This way you can be totally sure, which object you are accessing.
Maybe somewhere you have passed the first instance byref to one of your controls, stuffed it in a local variable, and now you are continuing to work with that local variable, wich indeed points to the first instance of the jobclass.
 
Aha, I have solved this at last, taken me all afternoon!

There was no code in the constructor that would cause an error, however I had not included a line to declare a table object, a requirement for my particular setup.

Two things I have learned from this:

1. Check my code thoroughly before posting

2. A handy tip on how to test which constructor is being access, I'm sure this help snippet will be useful.....thanks
 
I always thought it was good coding practise to build the construtors in such a manner that one is just a specialization og the other (i.e. a superset of operations is being made). Or, in other words, the parameterless constructor should always be called in the "parametered" constructors.

Well. I thats what I thought.
 
Back
Top