Hello,
is there a possibility to create in c# a indexed property that can be used in visual basic 6? I already tried to implement a indexer class object that implements the this indexer but this doesn't work.
Please Help
Printable View
Hello,
is there a possibility to create in c# a indexed property that can be used in visual basic 6? I already tried to implement a indexer class object that implements the this indexer but this doesn't work.
Please Help
you can't create an indexed property (other than the this property), but you can have a property that is an array, dictionary or any other collection, and would therefore be accessible with an index.
Code:public class Foo {
List<int> values = new List<int>;
public List<int> Values {
get { return values; }
}
}
public class Program {
public static void Main() {
Foo f = new Foo();
f.Values.Add(11);
int x = f.Values[0]; // x will be 11
}
}
Hello,
first thanks for your reply. I tried this, but visual basic 6 is not able to invoke the indexed property. I get the Error "Wrong number of argument or unknown property assignment" (I translated this from german :-))
Thanks
I'm not very surprised this doesn't work - generics don't translate to COM.
Try returning a System.Collections.IList (i.e. non-generic) like this instead :
I've tried accessing this in native C++ via COM and it works ok for me so it should work as required in VB6.Code:[Guid("0264699d-0113-43db-84fc-8e40ee12a04e")]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface IExample
{
System.Collections.IList List { get; }
}
[Guid("730e035e-fa90-47ec-b0b8-c23710b96b1b")]
public class Example : IExample
{
List<int> _list;
public Example()
{
_list = new List<int>();
_list.Add(1);
_list.Add(2);
_list.Add(3);
}
#region IExample Members
public System.Collections.IList List
{
get { return _list; }
}
#endregion
}
Darwen.
Thanks again for your reply :-)
My code look like this:
and I get the same error....Code:private List<double> SearchXVals = new List<double>();
public System.Collections.IList SearchX
{
get
{
return SearchXVals;
}
}
Try using the 'Item' method in VB e.g.
Darwen.Code:Dim xx As ...Example;
Dim d As Double;
Set d = xx.SearchX.Item(3);
Hi again,
the problem is that I cannot change the vb-code. It is part of a plugin architecture that was implemented and developed some time ago and there are a lot of plugins that use the already defined interface. So the only chance is to change the c# code to work with the vb-code. The other direction is not possible....
Thanks again for your reply
You should have mentioned this in the first place...
Do you have an example of a COM object which does work ? Examine its dll using OLE/COM viewer ("C:\Program Files\Microsoft Visual Studio 8\Common7\Tools\Bin\OleView.exe") and post what interfaces the working COM objects implement.
Darwen.
Hello darwen,
first thanks a lot for all your replays and your efforts.
Here is an example project that tries to access the indexed property of the c#-Com-module:
and here is my c# implementationCode:Private Sub Form_Load()
On Error GoTo Fehler
Dim object As Object
Set object = CreateObject("IS_Gateway_COM_Plugin.IS_COMGatewayPlugin")
object.SearchX(1) = 2#
Exit Sub
Fehler:
MsgBox "Error: " & Error
Unload Form1
End Sub
But I always get the error: "Wrong number of arguments or invalid property assignment"Code:private List<double> SearchXVals = new List<double>();
public System.Collections.IList SearchX
{
get
{
return SearchXVals;
}
}
Thanks again :-)