.Net Interop: example in using arrays/collections

AdministratorAdministrator Member, Moderator, Administrator Posts: 2,500
edited 2014-05-07 in Download section
.Net Interop: example in using arrays/collections
I just created this example to explain how .Net Interop can be used what you need Arrays.

You can read all about it on my blog.

http://www.mibuso.com/dlinfo.asp?FileID=1342

Discuss this download here.

Comments

  • jlandeenjlandeen Member Posts: 524
    This example code and the related blog post are an excellent example of some of the simple power that can come from using the base .NET framework inside NAV. The beauty of using base .NET functionality is that base platform is freely available and normally already required to be installed on servers and machines already - which means no custom COM Controls or DLL files that need to be managed and rolled out.

    Great simple example and I can't wait to see some more complex examples of .NET interop!!
    Jeff Landeen - Sr. Consultant
    Epimatic Corp.

    http://www.epimatic.com
  • WaldoWaldo Member Posts: 3,412
    working on it :wink:

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • IsakssonMiIsakssonMi Member Posts: 77
    Passing an array of BSTR (or whatever COM-type) from NAV by COM-interop would be nice :)
  • jordi79jordi79 Member Posts: 275
    I am having some problems with the DotNet Idictionary. The code in In your example:
        BEGIN
          dict := dict.Dictionary();
    
          dict.Add(1,'one');
          dict.Add(2,'two');
    
          FOR i := 1 TO dict.Count() DO BEGIN
            dict.TryGetValue(i,mytext);
            MESSAGE(mytext);
          END;
    

    But what if you do not know the key value, and you just want to iterate and print all values in the IDic? I have been trying to look for this for hours now. What I am doing is that I am using IDic to store the results for an XML function, but for the life of me do not know how to iterate Idic to retrieve the values I want.
  • jordi79jordi79 Member Posts: 275
    You know what, I found the answer. I was wondering why there was the Dotnet subtype SortedDictionary, and SortedDictionary+Enumerator.
    Name	DataType	Subtype	Length
    XPathNavigator	DotNet	System.Xml.XPath.XPathNavigator.'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    IDicEnum	DotNet	System.Collections.Generic.SortedDictionary`2+Enumerator.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    IDic	DotNet	System.Collections.Generic.SortedDictionary`2.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    TempStr	Text		250
    
    
    FileName := 'c:\temp\temp1.xml';
    FileName := FileMgmt.UploadFileSilent(FileName);
    IF NOT EXISTS(FileName) THEN EXIT;
    f.OPEN(FileName);
    f.TEXTMODE(TRUE);
    f.CREATEINSTREAM(FileInStream);
    XMLDoc.Load(FileInStream);
    RootNode := XMLDoc.DocumentElement;
    XPathNavigator := RootNode.CreateNavigator;
    IDic := XPathNavigator.GetNamespacesInScope(XMLNameSpaceScope.All);
    IDicEnum := IDic.GetEnumerator;
    WHILE IDicEnum.MoveNext DO BEGIN
      IDic := IDicEnum.Current;
      TempStr := IDic.ToString;
      MESSAGE(TempStr);
    END;
    

    What the above code does is that it will get all name spaces in the xml file and store in Idic, and later using IdicEnum, it will iterate Idic and print all contents from IDic.
Sign In or Register to comment.