I need to transform some .net code and there they have used a TryCast operator (https://docs.microsoft.com/en-us/dotnet/articles/visual-basic/language-reference/operators/trycast-operator)
Is there some alternative that we can use in OpenEdge?
DEFINE VARIABLE objAsConvertible AS IConvertible NO-UNDO. IF TYPE-OF(obj, IConvertible) THEN objAsConvertible = CAST(obj, IConvertible). IF NOT VALID-OBJECT(objAsConvertible) THEN RETURN obj:GetClass():TypeName + " does not implement IConvertible". ELSE RETURN "Type code is " + objAsConvertible:GetTypeCode.
DEFINE VARIABLE objAsConvertible AS IConvertible NO-UNDO. IF TYPE-OF(obj, IConvertible) THEN objAsConvertible = CAST(obj, IConvertible). IF NOT VALID-OBJECT(objAsConvertible) THEN RETURN obj:GetClass():TypeName + " does not implement IConvertible". ELSE RETURN "Type code is " + objAsConvertible:GetTypeCode.
Hi Simon,
Tried this and it compiles but it doesn't work as expected.
Maybe the original code that I want to port to Progress is wrong or maybe I did something wrong.
I see that you do the cast with an interface. Is that needed or can it be another class.
Code that I try to port:
If TryCast(RadGrid1.CurrentRow, GridViewDataRowInfo) IsNot Nothing Then ....
This is what I have now:
def var o as Telerik.WinControls.UI.GridViewDataRowInfo no-undo.
IF TYPE-OF(RadGridView1:CurrentRow, Telerik.WinControls.UI.GridViewDataRowInfo) then
assign o = CAST(RadGridView1:CurrentRow, Telerik.WinControls.UI.GridViewDataRowInfo).
Is that ported ok??
Mike/Simon,
Thanks, I can use your suggestion as replacement for TryCath.
It didn't solve my problem but I guess that the code that I wanted to port is also not correct.
Found another way to accomplish what I want but still thanks for your input
regards
Didier