General XMetaL Discussion

XMetaL Community Forum General XMetaL Discussion Unable to call Range method GreaterThan from C#/COM-Interop

  • freyp576

    Unable to call Range method GreaterThan from C#/COM-Interop

    Participants 2
    Replies 3
    Last Activity 11 years, 9 months ago

    Hi Derek

    we are rewriting (part of) our old VB6 code using C# and accessing the XMetaL API through COM Interop. We are using Visual Studio 2008 and XMetaL 6.0

    how can we call the IsGreaterThan/IsLessThan/IsEqual methods on a Range object
    to compare it with an other range? COM Interop seems to provide IsGreaterThan as get_IsGreaterThan, strange.

    Trying to do the following:

    done = !(oRange.get_IsGreaterThan(oRangeLeft) && oRange.get_IsLessThan(oRangeRight)) || oRange.get_IsEqual(oRangeOld);

    causing an error, “Keine Überladung für die get_IsGreaterThan-Methode nimmt 1 Argumente an.”
    or in english, no overload for the get_IsGreaterThan method takes 1 arguments

    also, it would be nice to do something like that:

                done = !((oRange > oRangeLeft) && (oRange < oRangeRight)) || oRange.get_IsEqual(oRangeOld); but this results in: Fehler  Der Operator “>” kann nicht auf Operanden vom Typ “XMetaL.Range” und “XMetaL.Range” angewendet werden.

    (the operator … cannot be applied to operands of type …)

    Is there a way to use XMetaL API/Range objects through COM Interop from C# code?
    Are there samples how to do that?

    Reply

    Derek Read

    Reply to: Unable to call Range method GreaterThan from C#/COM-Interop

    Microsoft has some tutorials on COM interop for C# here that might help:
    http://msdn.microsoft.com/en-us/library/aa645712%28v=VS.71%29.aspx

    Note that some of this help is written specifically for VS 2003, 2005 or 2008. I'm not sure how much it varies, but they do have different pages for some versions.

    Reply

    freyp576

    Reply to: Unable to call Range method GreaterThan from C#/COM-Interop

    Hi Derek,

    thanks for the link. I will check that.

    Also, I found the cause of my problem in the meantime. IsGreaterThan has an additional argument – and no default value when called from C#:

    bool get_IsGreaterThan(XMetaL.Range Selection, bool OrEqual)
        Member von XMetaL.Selection

    so after passing false as value for the second argument, I was able to solve my problem.

    best regards,
    Peter Frey

    Reply

    Derek Read

    Reply to: Unable to call Range method GreaterThan from C#/COM-Interop

    There's another good article here specifically on this subject and how different versions of C# handle parameters:
    http://msdn.microsoft.com/en-us/library/dd264739.aspx

    Scroll down to the section labelled “COM Interfaces” for information that will relate directly to how you write your code to interact with XMetaL (or anything else via COM). I have not tested the C# 4.0 feature they discuss here called “named and optional arguments”, but if it works for MS Office applications using COM then in theory it should work for anything.

    Reply

  • You must be logged in to reply to this topic.

Lost Your Password?

Products
Downloads
Support