I have a VB6 project that currently Compiles even though I am accessing a Property that does not exist.
The code looks a bit like this:
Public vizSvrEmp As VizualServer.Employees
Set vizSvrEmp = New VizualServer.Employees
Fn = FreeFile
Open vizInfo.Root & "FILE.DAT" For Random As #Fn Len = RecLen
Do While Not EOF(Fn)
Get #Fn, , ClkRecord
With vizSvrEmp
Index = .Add(ClkRecord.No)
.NotAvailable(Index) = ClkRecord.NotAvailable
.Bananas(Index) = ClkRecord.Start
'Plus lots more properties
End With
Loop
The Bananas property does not exist in the object yet it still compiles.
My vizSvrEmp Object is a .NET COM Interop DLL and is early bound and if I type the dot in I get the Intellisense correctly (which does not show Bananas)
I tried removing the With but that behaves the same
How can I make sure these errors are picked up by the compiler?
I know you’ve got this sorted out with the help of Hans but just for completeness, the alternative to using
ClassInterface(ClassInterfaceType.AutoDual)is to useClassInterface(ClassInterfaceType.None)and then Implement an explicit interface that is decorated withInterfaceType(ComInterfaceType.InterfaceIsDual)>.It is more work, but gives you complete control over the interface GUIDs. The AutoDual will auto generate unique GUIDs for the interfaces when you compile, which is time saving but you don’t have control over them.
In use, this would look something like this:
Note how the GUIDs are declared. I find creating a helper class to consolidate the GUIDs and provide Intellisense works out well:
Finally, I use these at the assembly level: