To use an automation object from within JADE, you simply create an instance of the JADE class (that is, a subclass of the ActiveXAutomation class) that corresponds to the automation object. The
A reference is established between the automation class and its default interface. You can then call JADE automation class methods as you can for any other JADE class. These method calls are passed by the default interface to the actual automation object.
If the automation object returns a reference to another interface in response to a method call or the getting of a property, JADE creates an instance of the corresponding JADE interface class and returns a reference to that instance instead. (A mapping is maintained between JADE interface instances and automation server interface instances.)
You can create only transient instances of ActiveXAutomation subclasses.
The following example is a Workspace or JadeScript method that loads three Excel cells with data, draws a chart, and prints the result.
chartExample(); vars xl : ExcelApp; // ActiveX automation subclass wrkSht : Worksheet; // interface subclass of the IDispatch class sht : I_Worksheet; // interface subclass of the IDispatch class rng : Range; // interface subclass of the IDispatch class chrts : Sheets; // interface subclass of the IDispatch class chrt : I_Chart; // interface subclass of the IDispatch class begin // Start Excel create xl; xl.createAutomationObject; xl.visible := true; // See what’s going on xl.workbooks.add(xl.XlWorksheet); // Add Workbook (with one sheet) sht := xl.activeSheet.I_Worksheet; // Get top sheet and fill cells sht.range("A1", null).putValue("One"); sht.range("B1", null).putValue("Two"); sht.range("C1", null).putValue("Three"); sht.range("A2", null).putValue(10); sht.range("B2", null).putValue(5); sht.range("C2", null).putValue(3); rng := sht.range("A1", "C2"); // Select cells chrts := xl.charts; // Add a chart chrts.add(null, null, null, null); chrt := xl.activeChart; // Start chart wizard chrt.chartWizard(rng, // source xl.Xl3DPie, // gallery 7, // format xl.XlRows, // plotBy 1, // categoryLabels 0, // seriesLabels 2, // hasLegend "Jade Example", // title null, // categoryTitle null, // valueTitle null); // xtraTitle // Output chart chrt.printOut(null, // first page null, // last page null, // copies null, // preview null, // printer null, // print to file null); // collate epilog if xl <> null then xl.activeWorkbook.saved := true; // Don't ask to save! xl.quit; // Close down Excel delete xl; endif; end;