CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Peter's Gekko

public Blog MyNotepad : Imho { }

COM variant arrays and .NET

Many a COM server exchanges data with its clients using so called variant arrays. These can contain anything you can imagine. Creating a variant array from a COM client can be a hassle. The Delphi VCL framework has the VarArrayCreate function to help you. Creating a variant array from a .NET COM client is even easier as an array of objects is compatible. Take this snippet where a COM server (sp) member expects an array containing variant bools. The array is declared as an array of object. It's members are filled with booleans.

object[] weeks = new object[sp.ActiveCollege.WeeksPerYear];

 

long match = 1;

for (int i = 0; i < 53; i++)

{

   if ((match & inAct.WeekPatroon) != 0)

       weeks[i] = true;

   else

       weeks[i] = false;

}

 

WeekInYearPattern wp = sp.ActiveCollege.CreateWeekInYearPattern();

wp.PatternAsArray = weeks;

 

The COM-object wp, has a variant array typed property PatternAsArray which  is completely satisfied with the object[]. No conversions, no hassle. Almost to easy to be true.


Published Feb 03 2006, 07:46 AM by pvanooijen
Filed under:

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add
Check out Devlicio.us!

This Blog

Syndication

News