4

I am an amator astronomer and I write driver for telescope with Delphi and the standard ASCOM First a special thank to David Heffernan who has helped me a lot these 2 last months. I have made a lot of progress in the writing of drivers, and there is a judge: 'Conform', a program which test all the compatibilties of a driver. At the beginning it was very bad, and now I am on the good way. The last really unsolved problem is an ArrayList of string. The documentation of Ascom Telescope driver has a property:

C#

ArrayList SupportedActions { get; }

Visual Basic:

ReadOnly Property SupportedActions As ArrayList
Get

Visual C++

property ArrayList^ SupportedActions {
  ArrayList^ get ();
}

Field Value
An ArrayList of strings (SafeArray collection) containing the names of supported actions.An array list collection has been selected as the vehicle for action names in order to make it easier for clients to determine whether a particular action is supported. This is easily done through the Contains method. Since the collection is also ennumerable it is easy to use constructs such as For Each ... to operate on members without having to be concerned about hom many members are in the collection.

Collections have been used in the Telescope specification for a number of years and are known to be compatible with COM. Within .NET the ArrayList is the correct implementation to use as the .NET Generic methods are not compatible with COM.

So I have tried to make an automation object:

enter image description here

And the big judge "Conform" program send me that (sorry it's a translation of an error message in french):

ERROR .NET - Exception: System.InvalidCastException: Impossible to make a cast of a COM object of type 'System.__ComObject' in type of class 'System.Collections.ArrayList'. The instances of type representing COM component, can't be casted in types different from representing COM components; however they can be casted in interfaces until the COM component underlying takes in charge the calls QueryInterfacefor the IID of the interface!!!!!!!!!!!!!!!!??????????????

Chinese or old Greek are more obvious for me. The only thing I have found is that in regedit:

enter image description here

Thanks again for your help. For your eyes only, a picture made with my telescope and some home-writed program:

enter image description here

fantaghirocco
  • 4,761
  • 6
  • 38
  • 48
michastro
  • 91
  • 9
  • Why don't you use a TStringList instead? Don't try to use .NET objects when Delphi has quite a number of suitable equivalent objects. Take a look at `TList` (the Delphi equivalent of `ArrayList`), `TList`, `TObjectList`, `TObjectList`and `TStringList`, just to name a few. – Rudy Velthuis Sep 07 '15 at 16:14
  • What don't really know is what your goal is. You have a .net component that you need to consume from Delphi? Is that it? Not sure why you didn't just use C#. – David Heffernan Sep 07 '15 at 19:04
  • @Rudy If the component is a .net component, how will using Delphi classes help. That just leads to the mirror problem. Delphi can use TStringList but the .net code cannot. – David Heffernan Sep 07 '15 at 19:05
  • Hello, I think that the program wich test my driver wait for a component of type `System.Collections.ArrayList`. In the an other part of my driver, I have been able to use IEnumerator with: `importlib("mscorlib.tlb");`. I know nothing about C# and I love Delphi :-(. – michastro Sep 07 '15 at 23:45
  • At the end, is it possible to use a .net component with Delphi? – michastro Sep 08 '15 at 00:31
  • It's a complex area, interop between .net and Delphi. Going to be hard for Delphi to serve up a .net type. Requires some tricky interop. Just learn C# and move on. It's a wonderful language. Easy if you know Delphi. – David Heffernan Sep 08 '15 at 04:31
  • Ok, somehow I don't get it. Does he have to pass an ArrayList to .NET? Then I really wonder why this part is not done in .NET. – Rudy Velthuis Sep 08 '15 at 06:19
  • @Rudy I'm not sure where the data flows but is seems clear this is an interop mismatch. Doing the whole task in C# is the obvious approach. – David Heffernan Sep 08 '15 at 12:21
  • @David; ,,, or VB or whatever he likes. ISTM that those who require people to pass an ArrayList expect people to use .NET. I wouldn't like that. – Rudy Velthuis Sep 08 '15 at 12:27
  • @Rudy Plenty of interop options available. Just not simple for non experts in the field of interop. – David Heffernan Sep 08 '15 at 12:35
  • Still, if I write something (in C# or whatever) to be used by many people, I do not use .NET specific data types like ArrayList, just POD types or types that can easily be interop-ed with other. non-.NET languages. – Rudy Velthuis Sep 08 '15 at 13:00
  • @Rudy That's then a pain in the neck for anyone using .net. Lowest common denominator. – David Heffernan Sep 09 '15 at 06:34
  • Perhaps a slight pain in the, er, neck, but doable. Passing an ArrayList from a non-.NET program is much more problematic, if possible at all. – Rudy Velthuis Sep 10 '15 at 12:33

1 Answers1

1

The solution was so simple!!! I found it on a web page. You want an ArrayList from .net?? Make it:

function TTelescope.Get_SupportedActions: OleVariant;
var
  capacity: Integer;
  item:Variant;
  dotNetArrayList:Variant;
begin
{ Create object }
  dotNetArrayList := CreateOleObject('System.Collections.ArrayList');


{ Add an element }
  dotNetArrayList.Add('Un élément chaîne');
  item := dotNetArrayList.Item(0);
  Result:=dotNetArrayList;
end;

And it's working perfectly. Nevertheless, thanks a lot for your answers, and perhaps a day I will try to learn C#.

michastro
  • 91
  • 9