COM Object setting a property problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andrew Mueller

    #1

    COM Object setting a property problem

    Hello all,

    I am working on a project, converting code from VB 6.0 to C#. I have a
    COM object (SDK.dll) referenced and am having some issues using it. I don't
    think it is specific to the object as much as it is specific to how either
    C# or the CLR allows the use of different parameters and variables... This
    is just a guess. Anyway, here is the problem:


    In VB:

    Dim iDRS as iH_SDK.DataReco rdset

    set iDRS = ConnectedServer .Data.NewRecord set

    With iDRS
    .Criteria.Filte rTagSet = True
    .Criteria.Filte rTag = fullTagName
    End with


    In C#

    iH_SDK.DataReco rdset iDRS = ConnectedServer .Data.NewRecord set();

    iDRS.Criteria.F ilterTagsSet = true;

    iDRS.Criteria.F ilterTag = fullTagName;


    --> On the last line in the C# program, I get a compile error of:

    Property, indexer, or event 'FilterTag' is not supported by the
    language; try directly calling accessor methods
    'IH_SDK._DataCr ieteria.get_Fil terTag()' or
    'iH_SDK._DataCr iteria.set_Filt erTag(ref string)'


    Any idea what I am doing wrong? I have tried a whole bunch of stuff without
    a solution yet and I am at the end of my long rope.



    Thanks in advance!!

    Andrew Mueller



  • Andrew Mueller

    #2
    Re: COM Object setting a property problem

    Looking even furthur into it.....

    The FilterTagSet is a property of the Criteria object of type Boolean.... It
    works fine and can be set without issue.

    The FilterTag is a property of the Criteria object of type String....
    doesn't work fine.

    Is this a COM / interop issue??? How do I get around it??



    "Andrew Mueller" <amueller@ins3. com> wrote in message
    news:uYEU0e6SDH A.3700@tk2msftn gp13.phx.gbl...[color=blue]
    > Hello all,
    >
    > I am working on a project, converting code from VB 6.0 to C#. I have[/color]
    a[color=blue]
    > COM object (SDK.dll) referenced and am having some issues using it. I[/color]
    don't[color=blue]
    > think it is specific to the object as much as it is specific to how either
    > C# or the CLR allows the use of different parameters and variables... This
    > is just a guess. Anyway, here is the problem:
    >
    >
    > In VB:
    >
    > Dim iDRS as iH_SDK.DataReco rdset
    >
    > set iDRS = ConnectedServer .Data.NewRecord set
    >
    > With iDRS
    > .Criteria.Filte rTagSet = True
    > .Criteria.Filte rTag = fullTagName
    > End with
    >
    >
    > In C#
    >
    > iH_SDK.DataReco rdset iDRS = ConnectedServer .Data.NewRecord set();
    >
    > iDRS.Criteria.F ilterTagsSet = true;
    >
    > iDRS.Criteria.F ilterTag = fullTagName;
    >
    >
    > --> On the last line in the C# program, I get a compile error of:
    >
    > Property, indexer, or event 'FilterTag' is not supported by the
    > language; try directly calling accessor methods
    > 'IH_SDK._DataCr ieteria.get_Fil terTag()' or
    > 'iH_SDK._DataCr iteria.set_Filt erTag(ref string)'
    >
    >
    > Any idea what I am doing wrong? I have tried a whole bunch of stuff[/color]
    without[color=blue]
    > a solution yet and I am at the end of my long rope.
    >
    >
    >
    > Thanks in advance!!
    >
    > Andrew Mueller
    >
    >
    >[/color]


    Comment

    • Simon Trew

      #3
      Re: COM Object setting a property problem

      But it looks like the reference to the string object must be passed by
      reference:
      [color=blue][color=green]
      > > 'iH_SDK._DataCr iteria.set_Filt erTag(ref string)'[/color][/color]

      Don't know why this is the case-- but did you *try* using the above line
      instead i.e.:

      iH_SDK._DataCri teria.set_Filte rTag(ref fullTagName)

      If so what was the result?

      S.

      "Andrew Mueller" <amueller@ins3. com> wrote in message
      news:eWnnKj6SDH A.2460@TK2MSFTN GP10.phx.gbl...[color=blue]
      > Looking even furthur into it.....
      >
      > The FilterTagSet is a property of the Criteria object of type Boolean....[/color]
      It[color=blue]
      > works fine and can be set without issue.
      >
      > The FilterTag is a property of the Criteria object of type String....
      > doesn't work fine.
      >
      > Is this a COM / interop issue??? How do I get around it??
      >
      >
      >
      > "Andrew Mueller" <amueller@ins3. com> wrote in message
      > news:uYEU0e6SDH A.3700@tk2msftn gp13.phx.gbl...[color=green]
      > > Hello all,
      > >
      > > I am working on a project, converting code from VB 6.0 to C#. I[/color][/color]
      have[color=blue]
      > a[color=green]
      > > COM object (SDK.dll) referenced and am having some issues using it. I[/color]
      > don't[color=green]
      > > think it is specific to the object as much as it is specific to how[/color][/color]
      either[color=blue][color=green]
      > > C# or the CLR allows the use of different parameters and variables...[/color][/color]
      This[color=blue][color=green]
      > > is just a guess. Anyway, here is the problem:
      > >
      > >
      > > In VB:
      > >
      > > Dim iDRS as iH_SDK.DataReco rdset
      > >
      > > set iDRS = ConnectedServer .Data.NewRecord set
      > >
      > > With iDRS
      > > .Criteria.Filte rTagSet = True
      > > .Criteria.Filte rTag = fullTagName
      > > End with
      > >
      > >
      > > In C#
      > >
      > > iH_SDK.DataReco rdset iDRS = ConnectedServer .Data.NewRecord set();
      > >
      > > iDRS.Criteria.F ilterTagsSet = true;
      > >
      > > iDRS.Criteria.F ilterTag = fullTagName;
      > >
      > >
      > > --> On the last line in the C# program, I get a compile error of:
      > >
      > > Property, indexer, or event 'FilterTag' is not supported by the
      > > language; try directly calling accessor methods
      > > 'IH_SDK._DataCr ieteria.get_Fil terTag()' or
      > > 'iH_SDK._DataCr iteria.set_Filt erTag(ref string)'
      > >
      > >
      > > Any idea what I am doing wrong? I have tried a whole bunch of stuff[/color]
      > without[color=green]
      > > a solution yet and I am at the end of my long rope.
      > >
      > >
      > >
      > > Thanks in advance!!
      > >
      > > Andrew Mueller
      > >
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Andrew Mueller

        #4
        Re: COM Object setting a property problem

        I have tried that, but I got the error:

        An object reference is required for the nonstatic field, method, or
        property 'iH_SDK._DataCr iteria.set_Filt erTag(ref string)'

        I believe this is mainly because I have not created an object
        iH_SDK._DataCri teria. The reason I did not create this object is because
        the iDRS points to a specific instance of a RecordSet object and the
        iH_SDK._DataCri teria would be pointing to a generic one.

        That is why I have been trying to set that property directly, as I would
        thing would make sense. It is very easy to do this in VB 6.0. I would
        think that it would not be this difficult. There must be some way to set
        that property if I can set the other property.

        Andy


        "Simon Trew" <ten.egnaro@wer ts> wrote in message
        news:uSjmQm6SDH A.304@tk2msftng p13.phx.gbl...[color=blue]
        > But it looks like the reference to the string object must be passed by
        > reference:
        >[color=green][color=darkred]
        > > > 'iH_SDK._DataCr iteria.set_Filt erTag(ref string)'[/color][/color]
        >
        > Don't know why this is the case-- but did you *try* using the above line
        > instead i.e.:
        >
        > iH_SDK._DataCri teria.set_Filte rTag(ref fullTagName)
        >
        > If so what was the result?
        >
        > S.
        >
        > "Andrew Mueller" <amueller@ins3. com> wrote in message
        > news:eWnnKj6SDH A.2460@TK2MSFTN GP10.phx.gbl...[color=green]
        > > Looking even furthur into it.....
        > >
        > > The FilterTagSet is a property of the Criteria object of type[/color][/color]
        Boolean....[color=blue]
        > It[color=green]
        > > works fine and can be set without issue.
        > >
        > > The FilterTag is a property of the Criteria object of type String....
        > > doesn't work fine.
        > >
        > > Is this a COM / interop issue??? How do I get around it??
        > >
        > >
        > >
        > > "Andrew Mueller" <amueller@ins3. com> wrote in message
        > > news:uYEU0e6SDH A.3700@tk2msftn gp13.phx.gbl...[color=darkred]
        > > > Hello all,
        > > >
        > > > I am working on a project, converting code from VB 6.0 to C#. I[/color][/color]
        > have[color=green]
        > > a[color=darkred]
        > > > COM object (SDK.dll) referenced and am having some issues using it. I[/color]
        > > don't[color=darkred]
        > > > think it is specific to the object as much as it is specific to how[/color][/color]
        > either[color=green][color=darkred]
        > > > C# or the CLR allows the use of different parameters and variables...[/color][/color]
        > This[color=green][color=darkred]
        > > > is just a guess. Anyway, here is the problem:
        > > >
        > > >
        > > > In VB:
        > > >
        > > > Dim iDRS as iH_SDK.DataReco rdset
        > > >
        > > > set iDRS = ConnectedServer .Data.NewRecord set
        > > >
        > > > With iDRS
        > > > .Criteria.Filte rTagSet = True
        > > > .Criteria.Filte rTag = fullTagName
        > > > End with
        > > >
        > > >
        > > > In C#
        > > >
        > > > iH_SDK.DataReco rdset iDRS = ConnectedServer .Data.NewRecord set();
        > > >
        > > > iDRS.Criteria.F ilterTagsSet = true;
        > > >
        > > > iDRS.Criteria.F ilterTag = fullTagName;
        > > >
        > > >
        > > > --> On the last line in the C# program, I get a compile error of:
        > > >
        > > > Property, indexer, or event 'FilterTag' is not supported by the
        > > > language; try directly calling accessor methods
        > > > 'IH_SDK._DataCr ieteria.get_Fil terTag()' or
        > > > 'iH_SDK._DataCr iteria.set_Filt erTag(ref string)'
        > > >
        > > >
        > > > Any idea what I am doing wrong? I have tried a whole bunch of stuff[/color]
        > > without[color=darkred]
        > > > a solution yet and I am at the end of my long rope.
        > > >
        > > >
        > > >
        > > > Thanks in advance!!
        > > >
        > > > Andrew Mueller
        > > >
        > > >
        > > >[/color]
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • Mattias Sjögren

          #5
          Re: COM Object setting a property problem

          Andrew,
          [color=blue]
          > iDRS.Criteria.F ilterTag = fullTagName;[/color]

          Make that

          iDRS.Criteria.s et_FilterTag(re f fullTagName);




          Mattias

          --
          Mattias Sjögren [MVP] mattias @ mvps.org

          Please reply only to the newsgroup.

          Comment

          • Andrew Mueller

            #6
            Re: COM Object setting a property problem

            That works great! Thanks....

            Here is another one, though... And, if you can, could you explain what
            interop (If that is what changes things) is doing so that I can understand
            why I am doing this??

            I have another property of the criteria object called SamplingMode. This
            one is of type ihSamplingMode where:

            ihSamplingMode contains Calculated, CurrentValue, Interpolated, etc...

            Ultimately:
            Calculated = 6, CurrentValue = 1, Interpolated = 2 from an enumerated
            type.


            How do I set these properties? I have tried the same idea, but it doesn't
            like that.

            TRIED:

            int intSM = 1;

            iDRS.Criteria.s et_SamplingMode (ref intSM);

            ERROR:

            The best overloaded method match for
            'iH_SDK._DataCr iteria.set_Samp lingMode(ref iH_SDK.ihSampli ngMode)' has some
            invalid arguments.


            Thanks again!

            Andrew Mueller


            "Mattias Sjögren" <mattias.dont.w ant.spam@mvps.o rg> wrote in message
            news:ucDEn16SDH A.2260@TK2MSFTN GP12.phx.gbl...[color=blue]
            > Andrew,
            >[color=green]
            > > iDRS.Criteria.F ilterTag = fullTagName;[/color]
            >
            > Make that
            >
            > iDRS.Criteria.s et_FilterTag(re f fullTagName);
            >
            >
            >
            >
            > Mattias
            >
            > --
            > Mattias Sjögren [MVP] mattias @ mvps.org
            > http://www.msjogren.net/dotnet/
            > Please reply only to the newsgroup.[/color]


            Comment

            • Mattias Sjögren

              #7
              Re: COM Object setting a property problem

              Andrew,
              [color=blue]
              >Here is another one, though... And, if you can, could you explain what
              >interop (If that is what changes things) is doing so that I can understand
              >why I am doing this??[/color]

              The previous issue was due to the fact that C# only supports indexed
              (or parameterized) properties where the index arguments are passed by
              value. In COM, it was possible (and not uncommon) to pass them by
              reference instead. For such properties, you can't use the regular
              property syntax in C#, but must explicitly call the underlying set_
              method instead.

              This new problem seems to be a simple use of the wrong type, and not
              really interop related.

              [color=blue]
              > int intSM = 1;
              >
              > iDRS.Criteria.s et_SamplingMode (ref intSM);
              >
              >ERROR:
              >
              > The best overloaded method match for
              >'iH_SDK._DataC riteria.set_Sam plingMode(ref iH_SDK.ihSampli ngMode)' has some
              >invalid arguments.[/color]

              Since the method parameter apparently is of type ihSamplingMode, so
              should your local variable be. Using an int wont work. So change it to

              ihSamplingMode intSM = ihSamplingMode. CurrentValue;



              Mattias

              --
              Mattias Sjögren [MVP] mattias @ mvps.org

              Please reply only to the newsgroup.

              Comment

              Working...