[progress Communities] [progress Openedge Abl] Forum Post: Cast Vs Dynamic-cast

Status
Not open for further replies.
L

Lieven De Foor

Guest
Hi, Why is the compiler preventing me from casting an object from type a to type b when those two types are unrelated, while a dynamic-cast is working without problems? Such a compile-time check isn't happening in c# afaik (or it might be implemented differently, see stackoverflow.com/.../compile-time-and-runtime-casting-c-sharp) I think the compiler is incorrectly assuming this isn't a valid cast, which is proven by the dynamic-cast working without problems. E.g. INTERFACE IButton: END INTERFACE. CLASS ComponentFactory: METHOD PUBLIC STATIC IButton CreateButton(): RETURN NEW CustomButton(). END METHOD. END CLASS. CLASS CustomButton INHERITS System.Windows.Forms.Button IMPLEMENTS IButton: END CLASS. CLASS MyForm INHERITS Progress.Windows.Form: CONSTRUCTOR MyForm(): DEFINE VARIABLE OkButton AS IButton NO-UNDO. OkButton = ComponentFactory:CreateButton(). Controls:Add(CAST(OkButton, System.Windows.Forms.Control)). /* Isn't compiling */ Controls:Add(DYNAMIC-CAST(OkButton, "System.Windows.Forms.Control")). /* Works */ END CONSTRUCTOR. END CLASS.

Continue reading...
 
Status
Not open for further replies.
Top