From: pf@bilbo.bio.purdue.edu (Paul Furbacher)
Subject: Re: TurboVision Question (w/ example)
Followup-To: comp.lang.pascal
Organization: Purdue University
Date: Sun, 24 Jan 1993 02:12:58 GMT

At the risk of beating a dead horse ... or as
Bob Beauchaine would have, trying the cat experiment
for the 500th time....

In article <lm2b5fINNprv@earth.cs.utexas.edu>, 
preavley@cs.utexas.edu (Paul Reavley) wrote 
with regards to Berend de Boer's suggestion dispensing
with SetData() and GetData() overrides to effectively change 
the string pointed to by the TStaticText field "Text".
De Boer wrote:

> >The other writers used the Set- and GetData methods. Another thing
> >might be to override the Draw method of some selfmade View. That Draw
> >method can be display different texts by drawing some global variable
> >(most simple, not very TV-ish).
> etc....

To which Reavley replied:

>   Check out the TIndicator object at the bottom left hand corner
> of TEditWindow s in tvedit.pas.  I believe it uses the Draw method
> for such a purpose.  I expanded TIndicator to display overwrite/
> insert mode, pagenumber, column number, line number and line
> spacing.

It doesn't do what you suggest; instead, it uses a procedure called 
TIndicator.SetValue(). If you ponder this, it is just another
flavor of SetData().  But in order for it not to be confused 
with the latter which is primarily associated (conceptually)
with setting the data of a subview within a group, such as an
static text view within a dialog box, the TV designers probably
chose a different method name.  They also may have decided not 
to override the SetData method which typically takes an untyped 
record (basically a pointer) as a parameter.  Here, SetValue()
has two parameters: "aLocation and "aModified".

In addition, SetValue() forces a DrawView which violates the
spirit of SetData().  There may have been other reasons for 
creating a separate but nearly identical method, but only 
your TV authors know.

As you can see, TIndicator is not an example of what de Boer
suggested, that is, to have the Draw method pop the contents 
of a global string into a TDrawBuffer and display it.  His
notion was that the global string would be accessible from
anywhere in the program, and when the static text had to 
redraw itself it would take as its text that held in
the global string variable.  He is correct in suggesting
that this violates the object-oriented paradigm of data and
methods which together form an encapsulated object.  Instances 
should receive messages which prompt action based on the content
of the message.  Therefore, global variables shouldn't be 
necessary, but they are not always avoidable.  In this case,
however, a global variable is completely avoidable, and 
many would recommend not using one.  

Rather, as S.A. Modena pointed out in an earlier 
post in this thread, override the correct methods, 
typically the HandleEvent() method of the descendent 
view to receive and send informative messages.  
Through messages which inform as to which 
command, and give the what or the where of the 
information, object instances "talk" to one another without
having to know each other (i.e., directly reference each other).
As Modena pointed out in his repost to Pollet, this is the 
preferred, and cleanest implementation given the language 
you are currently working with.   

[My goal has not been to criticize de Boer.  He knows that
he has made many good contributions to this discussion 
group.  And just yesterday, he wisened me up to something 
I had overlooked when giving advice on a TV question.  It 
turned out I was out in left field and he kindly set me 
straight.]

To those who are getting a little bored with this discussion,
thanks for reading the TV manual and  all the source 
code -- gobs of megabytes -- and thinking hard about what
TV and object-oriented programming is all about.  If more 
poured their hearts and souls into the endeavour, our discussions
would be more enlightening.  Perhaps.

Paul Furbacher
pf@bilbo.bio.purdue.edu
Newsgroups: comp.lang.pascal