Re: Should this be an object?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



If it were me, I'd leave the controls out of your object altogether.
Normally, the GUI takes care of the GUI and the object takes care of the
object. In other words, something like:

MyControl.Caption = MyObject.DataToShowUser

or

MyListBox.AddItem MyObject.DataToShowUser


Usually, the GUI is aware of what type of control it's using, so why try to
make your objects be aware of it as well? They probably don't need to be.



Rob


"MP" <NoSpam@xxxxxxxxxx> wrote in message
news:eYpNHlFtHHA.4688@xxxxxxxxxxxxxxxxxxxxxxx
Hi
Still trying to learn OO philosophy.

In project A I have an object, lets call it cUnit.
At some point cUnit will be asked to display some information about itself
to the user.
It has a property .DisplayObject to do the work of showing the info and a
method .Display to delegate to the object to do the work.

Maybe the data wants to show up in a label, or a textbox or a listbox, or
listview or treeview etc....depending on the object and the point in the
program and the type of data, etc

at this point for cUnit, the DisplayObject is hard coded to be a listbox
'cUnit
Public Property Set DisplayObject(oDisplayObject As ListBox)
Set moDisplayObject = oDisplayObject
End Property
and the .Display method is
Public Sub Display()
moDisplayObject.AddItem Me.DataToShowUser
End Sub

but for other objects they may only need to show their data in a label or
???
so their display method would be
Public Sub Display()
moDisplayObject.Caption = Me.DataToShowUser
End Sub
or if it were a textbox
Public Sub Display()
moDisplayObject.Text = Me.DataToShowUser
End Sub
etc

this seems too tightly coupled to the type of object doing the displaying
I have the thought to create a class cDisplayObject which could be set to
any appropriate type as req'd

Then cUnit.DisplayObject (and any other class that needs a DispObj)
becomes
Public Property Set DisplayObject(oDisplayObject As cDisplayObject)
Set moDisplayObject = oDisplayObject
End Property
and all classes that had a .Display method would use
Public Sub Display()
moDisplayObject.Display Me.DataToShowUser
End Sub

then in cDisplayObject
Private moDispObj as Object
Sub Display(val)
'either a selectcase true on TypeOf or If/ElseIf grouping or ???

If TypeOf (moDispObj) Is TextBox Then
moDispObj.Text = cStr(Val)
ElseIf TypeOf (moDispObj) Is Label Then
moDispObj.Caption = CStr(Val)
ElseIf TypeOf (moDispObj) Is ListBox Then
moDispObj.AddItem CStr(Val)
etc, etc

End Sub

does this seem like the right direction to head?



.



Relevant Pages

  • Re: TextBox Update Problem
    ... 'Display next message in Message Center - this does not work ... Dim objPathOUT ... Public Sub OutPutFolder_Click(ByVal sender As System.Object, ...
    (microsoft.public.vb.general.discussion)
  • Should this be an object?
    ... In project A I have an object, lets call it cUnit. ... At some point cUnit will be asked to display some information about itself ... Public Sub Display() ... If TypeOf (moDispObj) Is TextBox Then ...
    (microsoft.public.vb.general.discussion)
  • Re: Change the Shapes Color
    ... This subroutine will display and change the line colour and the fill foreground colour of all the shapes on the current page. ... Public Sub Colour_Test1 ... Dim objshape As Visio.Shape ...
    (microsoft.public.visio.general)
  • Re: Change Text Value on Runtime
    ... Thanks for rich information and for links. ... Public Sub Progress(ByVal sender As Object, ByVal e As ProgressEventArgs) ... >> after every text box change, i display message box. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Change the Shapes Color
    ... This subroutine will display and change the line colour and ... Public Sub Colour_Test1 ... Dim objshape As Visio.Shape ...
    (microsoft.public.visio.general)