PowerBASIC doesn't seem to do much in the way of type checking on interface parameters.
Announcement
Collapse
No announcement yet.
passing interfaces - no type checking?
Collapse
X
-
-
I was wrong
No, I was wrong on that Chris, and its good you questioned it. I should have corrected that statement; right after your post I checked it and found the same thing you did; PowerBASIC doesn't seem to do much in the way of type checking on interface parameters.
Give me a second and I'll post the little piece of code I tried, and show some bizarre results.
Leave a comment:
-
Fred, I don't quite follow. Do you mean that even if the "wrong" interface pointer is supplied, the specified method will be retrieved if it exists?
Leave a comment:
-
If a class supports multiple interfaces, it has the capacity to hand out these interfaces in the form of virtual function table pointers to interested clients. Lets say a class contains an ix, iy, and iz interface, and you obtain an ix interface from the class in the usual manner. In either Visual Basic or PowerBASIC you'll get any of the other interfaces by doing something as simple as this...
iy = ix
What happens (under water) is that VB or PB performs a QueryInterface() call where one of the parameters of the call is the requested interface. If that interface is implemented within the class you'll get a valid interface pointer from the call that you can use.
Also, in PowerBASIC anyway, you can pass any interface to a routine because all interfaces ultimately have IUnknown as their 1st methods; i.e., all interfaces are polymorphs of IUnknown.
It seems you may have also stumbled onto the fact that passing an interface pointer causes a QueryInterface call if the interface passed is different from the type specified in the call.
Leave a comment:
-
Originally posted by Edwin Knoppert View PostImo it is invoking the desired interface under water.
If objptr differs from in and use i am right.
Leave a comment:
-
Imo it is invoking the desired interface under water.
If objptr differs from in and use i am right.
If the same.. we have a problem
Check out my items question.
property items As Interface2
property = Me
End property
PB invokes (queryinterface) the desired interface from the class.
Excellent stuff!!
Leave a comment:
-
So wouldn't represent better management of our expectations to pass all interfaces as type Interface ? - or would this not be right for COM?
Leave a comment:
-
Originally posted by Fred Harris View PostThe 'jump table' is the vtable Chris.
Leave a comment:
-
Passed UDT parameters aren't checked, either.. except for the SIZEOF(same). May be related.
Leave a comment:
-
passing interfaces - no type checking?
Blundering through a bit of coding this morning I noticed that if a parameter is passed AS <interfacename>, then the wrong interface can be supplied without any problems arising until the wrong interface method is called. My guess is that methods are accessed via a jump table rather than being called at explicit addresses like SUBs and FUNCTIONS. So all the "AS myinterface" does it to tell which jump table to use, and this "typing" is not enforced. I've only tried interfaces in the same CLASS so far. Can anyone confirm thsi?Tags: None
Leave a comment: