Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

One Method, multiple tasks

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • One Method, multiple tasks

    For members experienced with objects the following is probably 'old hat' but I couldn't find anything in the documentation mentioning its use.

    It is a simple way to have a single statement do more than one task depending upon the assigned Class.

    The 'trick' is to duplicate both an Interface name and a method name.

    The following snippet illustrates the concept.
    Code:
    #Compile  Exe
    #Dim All
    
    Macro CreateObj(ObjectName, ClassName) = ObjectName = Class ClassName
    Macro DestroyObj(ObjectName) = ObjectName=Nothing
    
    Class CShortDisplay
      
      Interface IDisplay: Inherit IUnknown
      
        Method Table() As Long
          ? "ShortDisplay"
        End Method
      
      End Interface
      
    End Class
    
    Class CFullDisplay
      
      Interface IDisplay: Inherit IUnknown
      
        Method Table() As Long
          ? "FullDisplay"
        End Method
      
      End Interface
      
    End Class
    
    Global ShowMy As IDisplay
    
    Function PBMain( ) As Long
                              
      CreateObj(ShowMy, "CShortDisplay")
      
      ShowMy.Table
      
      DestroyObj(ShowMy)
      
      CreateObj(ShowMy, "CFullDisplay")
      
      ShowMy.Table
      
      DestroyObj(ShowMy)
    
    '  Waitkey$
    
    End Function
Working...
X