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!!
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.
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.
Comments
Great simple example and I can't wait to see some more complex examples of .NET interop!!
Epimatic Corp.
http://www.epimatic.com
Eric Wauters
MVP - Microsoft Dynamics NAV
My blog
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.
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.