COM Object setting a property problem

A

Andrew Mueller

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.DataRecordset

set iDRS = ConnectedServer.Data.NewRecordset

With iDRS
.Criteria.FilterTagSet = True
.Criteria.FilterTag = fullTagName
End with


In C#

iH_SDK.DataRecordset iDRS = ConnectedServer.Data.NewRecordset();

iDRS.Criteria.FilterTagsSet = true;

iDRS.Criteria.FilterTag = 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._DataCrieteria.get_FilterTag()' or
'iH_SDK._DataCriteria.set_FilterTag(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
 
A

Andrew Mueller

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??
 
S

Simon Trew

But it looks like the reference to the string object must be passed by
reference:

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

iH_SDK._DataCriteria.set_FilterTag(ref fullTagName)

If so what was the result?

S.
 
A

Andrew Mueller

I have tried that, but I got the error:

An object reference is required for the nonstatic field, method, or
property 'iH_SDK._DataCriteria.set_FilterTag(ref string)'

I believe this is mainly because I have not created an object
iH_SDK._DataCriteria. 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._DataCriteria 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
 
A

Andrew Mueller

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.set_SamplingMode(ref intSM);

ERROR:

The best overloaded method match for
'iH_SDK._DataCriteria.set_SamplingMode(ref iH_SDK.ihSamplingMode)' has some
invalid arguments.


Thanks again!

Andrew Mueller
 
M

Mattias Sjögren

Andrew,
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??

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.

int intSM = 1;

iDRS.Criteria.set_SamplingMode(ref intSM);

ERROR:

The best overloaded method match for
'iH_SDK._DataCriteria.set_SamplingMode(ref iH_SDK.ihSamplingMode)' has some
invalid arguments.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top