DigiPara Liftdesigner LDX API
Loading...
Searching...
No Matches
Interfaces of an Object

Upcasting

Most objects in LDX support many interfaces. Ordinarily in COM, you use QueryInterface to cast between them; that is, unfortunately, not the way LDX is set up. Instead, for every logical X inherits Y relation, there is a property X.Y that allows you to cast up from X to Y.

As an illustration, here are the ways to cast up from ILDXCarFrame5 to its base classes ILDXMoveFrame5, ILDXComp5 and ILDXObject5:

classDiagram
      class ILDXObject5
      class ILDXCarFrame5
      class ILDXMoveFrame5
      class ILDXComp5

%% ILDXObject5 ..> ILDXComp5 : .Comp?
ILDXComp5 ..> ILDXObject5 : .Object
ILDXCarFrame5 ..> ILDXObject5 : .Object
ILDXMoveFrame5 ..> ILDXObject5 : .Object
ILDXCarFrame5 ..> ILDXMoveFrame5 : .MoveFrame
ILDXMoveFrame5 ..> ILDXComp5 : .Comp
ILDXCarFrame5 ..> ILDXComp5 : .Comp

These relations are listed in the See also section of the interface documentation.

Downcasting

Downcasting is always done from ILDXObject5.

If the object also implements ILDXComp5, that can be accessed with .Comp. If the interface is not implemented, that property is simply null.

To get to more specialized interfaces, we have two methods:

  • The recommended one is .GetLDXType. It expects as first argument the ObjectId corresponding to the interface you are looking for. If the interface is implemented, its IDispatch base is returned. If not, you get null. This is our version of QueryInterface, basically.
  • There is also the property .LDXType. That always contains the most derived type (or rather, the IDispatch base of it). This is fine for simple cases where only one possible most derived interface exists, but you cannot get to ILDXMoveFrame5 that way, as it is an intermediate interface with many more derived ones.

Both methods give you just an IDispatch. You should cast it to the desired LDX interface using as in C# and DirectCast in VB.NET. Check Retrieve specific interfaces for details.

Not recommended, as it is prone to surprising runtime errors: You can also just use the raw IDispatch with late binding. In C#, use the dynamic type. In VB.NET, use Object.

Next: Core Objects to Understand