Polymorphic Behavior in VB6

Posted by Tom Tresansky on Stack Overflow See other posts from Stack Overflow or by Tom Tresansky
Published on 2010-04-05T20:50:02Z Indexed on 2010/04/05 20:53 UTC
Read the original article Hit count: 316

Filed under:
|

I recently noticed the CallByName keyword in VB6.

Since this takes a object, procedure name, "call type" and arguments array, can this be used to "fake" some types of polymorphic behavior?

I can make 2 classes, class A and B, each with the same method Foo, and do:

Dim list As New Collection
Dim instanceA As New ClassA
Dim instanceB As New ClassB
Dim current As Object

Call list.Add(instanceA)
Call list.Add(instanceB)

For Each current in list
  Call CallByName(current, "methodName", vbMethod)
Next

Anyone done this before? Problems? Horrible idea or genius idea? Implications? Unintended consequences?

© Stack Overflow or respective owner

Related posts about vb6

Related posts about visual-basic