BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

newb? updating class's parent

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OO design
View previous topic :: View next topic  
Author Message
David Freeman
Guest





PostPosted: Sat Dec 10, 2005 6:05 pm    Post subject: newb? updating class's parent Reply with quote



I have the following class structure:

Tmoney = class
private
fvalue: double;
function getvalue: double read getvalue write setvalue
procedure setvalue(const value: double);
public
property value: double read getvalue write setvalue
end;

TLineItem = class
private
fischanged: boolean;
flinevalue: tmoney;
public
function getischanged: boolean;
function getlinevalue: double;
procedure setischanged(const value: boolean);
procedure setlinevalue(const value: double);
public
property ischanged: boolean read getischanged write setischanged;
property linevalue: double read getlinevalue write setlinevalue;
end;

In my code I have
thislineitem.ischanged := false;
thislineitem.linevalue.value := 0.00;
and later
calculations
thislineitem.linevalue.value := calculatedvalue;
I want thislineitem.ischanged set true here.

When flinevalue was a double, I could set fischanged := true in
..setlinevalue. However, as with flinevalue as a tmoney, .setlinvalue is not
used.

Is there any way of setting ischanged 'automatically' or do I just need to
remember to set it in code each time?

Note: tmoney is used in numerous other classes, only a few of which have
fischanged.
Note: Delphi 7 professional (still)

Thanks
David


Back to top
Lee_Nover
Guest





PostPosted: Sat Dec 10, 2005 6:35 pm    Post subject: Re: newb? updating class's parent Reply with quote



Quote:
Is there any way of setting ischanged 'automatically' or do I just need to
remember to set it in code each time?

you can use the Observer pattern
I use Joanna's implementation (explained here: http://blogs.teamb.com/joannacarter/articles/690.aspx)

Back to top
Bob Dawson
Guest





PostPosted: Sat Dec 10, 2005 8:48 pm    Post subject: Re: newb? updating class's parent Reply with quote




"David Freeman" wrote
Quote:
I have the following class structure:

Tmoney = class
private
fvalue: double;
function getvalue: double read getvalue write setvalue
//---seriously doubt above line Smile

// I'll assume that these are not real code.
Quote:
procedure setvalue(const value: double);
public
property value: double read getvalue write setvalue
end;

Don't create a new TMoney object but then leave responsibility for knowing
its status with the line item.

First, make TMoney track its own IsChanged value, then
ajust TLineItem to make GetIsChanged check its component parts. For now,
that would be

function TLineItem.GetIsChanged: boolean;
begin
Result := FIsChanged or FLineValue.IsChanged;
end;

Quote:
Is there any way of setting ischanged 'automatically' or do I just need to
remember to set it in code each time?

It ends up still getting set automatically, but at the TMoney level.

bobD



Back to top
Bob Dawson
Guest





PostPosted: Sat Dec 10, 2005 8:59 pm    Post subject: Re: newb? updating class's parent Reply with quote

"Lee_Nover" wrote

you can use the Observer pattern

Considerable overkill here, I think. If TLineItem needs to know if FMoney is
changed, it can just ask.

bobD


Back to top
David Freeman
Guest





PostPosted: Sat Dec 10, 2005 10:02 pm    Post subject: Re: newb? updating class's parent Reply with quote

Thanks guys, I think I will go with Bob's proposal, certainly simpler on the
surface and definitely adequate for what I want.

Thanks
David


Back to top
preston
Guest





PostPosted: Mon Dec 12, 2005 3:10 pm    Post subject: Re: newb? updating class's parent Reply with quote

Bob Dawson wrote:
Quote:
"Lee_Nover" wrote

you can use the Observer pattern

Considerable overkill here, I think.
bobD

Swinging a big hammer helps to keep ones body and mind in shape ;)


Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OO design All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.