Introduction
The transition from weak to strong typing is a very important consideration for all large-scale upgrade efforts. Generally speaking, VB6 will implicitly convert just about anything to anything. Also VB6 has various weak types: Object, Variant, Form, Control, as well as a weakly typed collection class, that allow programmers to defer type checks until runtime. Many COM APIs are exposed through weakly typed interfaces. To make matters worse, VB6 uses the same notation for a late call and an early call: the details are handled by VB6/COM runtime behind the scenes. On the other hand, the .NET languages, tend to favor strong type checking at compile time, and making late calls in .NET typically requires deliberate use of object-oriented design, interfaces, or late call syntax.
In general, gmStudio will attempt to upgrade Variants, and to a lesser degree Objects, to strong types by analyzing usage of the weakly typed symbols and the collection of all types defined to the source system. In most cases this produces cleaner, more correct, strongly typed code. However usage information is insufficient or ambiguous, selecting a single strong type is not possible and the upgraded code will retain the weaker types. In some situations, the tool must use techniques like CallByName, dynamic, temporary variables, and casting to make the weakly-typed code build in .NET. But, although the weakly-typed code builds, it may not run properly. Furthermore, some VB6 applications use weakly typed code very deliberately to implement more dynamic logic. When this is done, the upgraded code may need to be dynamic as well.
In order to help teams make the deal with with typing related upgrade issues, gmStudio has many for implementing an upgrade solution that either uses stronger types or implements more dynamic logic, depending on what is required. The commands for introducing stronger types are registry/fixtype, refactor/fixtype, modifying IDFs to have stronger types, and in some cases pre-edits to modify the original code. The commands for allowing dynamic types are refactor/generic, refactor/overload, use of the dynamic metatype, dictionaryAdd/CollectionAdd, and many others.
This article presents the techniques for improving how your upgrade solution handles weakly typed code.
ByRef object arguments taking with multiple types
VB6 is allows almost many implicit conversion
of actual arguments to formal argumentarguments, but C# does not. This is one of t
Consider rvarItem the following example. In the calling code, is used to return different types of variables from a weakly types collection:
...