Re: Abstract class variables question



On 2007-11-14 22:16:31 -0800, "tshad" <tfs@xxxxxxxxxxxxxx> said:

[...]
I did need to add a method Reset() to reset the _objInitial variable to be
whatever the _objCurrent is at the time as well as change the _fChange to
false.

This is to handle the situations, such as Database updates or inserts, where
we still want to use the same screen but have already updated the data.

That's fine. The class is for your use. You should put the features you need into it. :)

[...]
Actually, it compiles fine. But the problem is that the compiler won't let
me do the following in my code that calls these objects:

bool test;
BoolType booltemp = new BoolType(false);
booltemp.Data = true;
test = booltemp.Data;
test = booltemp.First;

I get an error on the last 2 lines.

Cannot implicitly convert type 'object' to 'bool'

I assume the method is supposed to handle that - but I don't think the
compiler sees the method.

No, the property I included as a convenience property (sorry for the misleading comment that says "method" :) ) needs to be used directly for it to be useful. It doesn't change how the base class properties behave.

So in your code, you could write this:

test = booltemp.TypedData;

and that would work.

You can also add a similar property for the first value:

public bool TypedFirst
{
get { return (bool)Data; }
set { Data = value; }
}

Then the second of the two lines causing an error would look like:

test = booltemp.TypedFirst;

Note that strictly speaking, the setter for the typed property isn't required, since the down-cast to Object works automatically with the base class property. I like having it though, just for the symmetry.

Hope that helps.

Pete

.