Package com.jacob.com

Examples of com.jacob.com.SafeArray


      // wrap the script control in a variant
      Variant v = new Variant(sControl);

      // create a safe array of type dispatch
      SafeArray sa = new SafeArray(Variant.VariantDispatch, 1);

      // put the variant in the array
      sa.setVariant(0, v);

      // take it back out
      Variant v2 = sa.getVariant(0);
      Dispatch d = v2.toDispatch();

      // make sure you can call eval on it
      result = Dispatch.call(d, "Eval", scriptCommand);
      assertTrue(result.toString().equals("6"));
View Full Code Here


    for (count = 1; count < MAX; count++) {
      int i = 0;
      try {
        ComThread.InitMTA();
        for (i = 0; i < count; i++) {
          SafeArray a1 = new SafeArray(Variant.VariantVariant, 2);
          a1.setVariant(0, new Variant("foo"));
          a1.setVariant(1, new Variant("bar"));
          Variant v = new Variant(a1);
          SafeArray a2 = v.toSafeArray(true);
          if (a2 == null) {
            System.out.println("got null back from toSafeArray()");
          }
        }
        ComThread.Release();
View Full Code Here

  public void testSafeArrayViaExcel() {

    ActiveXComponent xl = new ActiveXComponent("Excel.Application");
    try {
      Dispatch cell;
      SafeArray sAProdText;
      Dispatch workbooks = xl.getProperty("Workbooks").toDispatch();
      System.out.println("have workbooks");
      Dispatch workbook = Dispatch.call(
          workbooks,
          "Open",
          getWindowsFilePathToPackageResource(
              "SafeArrayViaExcel.xls", this.getClass()))
          .toDispatch();
      System.out.println("Opened File - SafeArrayViaExcel.xls\n");
      Dispatch sheet = Dispatch.get(workbook, "ActiveSheet").toDispatch();
      cell = Dispatch.invoke(sheet, "Range", Dispatch.Get,
          new Object[] { "A1:D1000" }, new int[1]).toDispatch();
      System.out.println("have cell:" + cell);
      sAProdText = Dispatch.get(cell, "Value").toSafeArray();
      System.out.println("sa: dim=" + sAProdText.getNumDim());
      System.out.println("sa: start row=" + sAProdText.getLBound(1));
      System.out.println("sa: start col=" + sAProdText.getLBound(2));
      System.out.println("sa: end row=" + sAProdText.getUBound(1));
      System.out.println("sa: end col=" + sAProdText.getUBound(2));
      int i;
      int lineNumber = 1;
      int n = 0;
      for (lineNumber = 1; lineNumber < 1000; lineNumber++) {
        for (i = 1; i < 4; i++) {
          System.out.println((n++) + " " + lineNumber + " " + i + " "
              + sAProdText.getString(lineNumber, i));
          /*
           * if (sAProdText.getString(lineNumber,i).compareTo("aaaa") !=
           * 0 ) { System.out.println("Invalid String in line " +
           * lineNumber + " Cell " + i + " Value = " +
           * sAProdText.getString(lineNumber,i)); stringFound = false; } }
View Full Code Here

  /**
   *
   */
  public void testShortSafeArray() {
    short sourceData[] = new short[] { 1, 2, 3 };
    SafeArray saUnderTest = new SafeArray(Variant.VariantVariant, 3);

    saUnderTest.fromShortArray(sourceData);
    short[] extractedFromSafeArray = saUnderTest.toShortArray();
    for (int i = 0; i < extractedFromSafeArray.length; i++) {
      assertEquals("" + i, sourceData[i], extractedFromSafeArray[i]);
    }

    assertEquals("single get failed: ", sourceData[2], saUnderTest
        .getShort(2));

    // test conversion
    int[] extractedFromSafeArrayInt = saUnderTest.toIntArray();
    for (int i = 0; i < extractedFromSafeArray.length; i++) {
      assertEquals("" + i, sourceData[i], extractedFromSafeArrayInt[i]);
    }
    // test conversion
    double[] extractedFromSafeArrayDouble = saUnderTest.toDoubleArray();
    for (int i = 0; i < extractedFromSafeArrayDouble.length; i++) {
      assertEquals("" + i, new Double(sourceData[i]).doubleValue(),
          extractedFromSafeArrayDouble[i]);
    }
    // test conversion
    Variant extractedFromSafeArrayVariant[] = saUnderTest.toVariantArray();
    for (int i = 0; i < extractedFromSafeArrayVariant.length; i++) {
      assertEquals("" + i, sourceData[i],
          extractedFromSafeArrayVariant[i].getShort());
    }
  }
View Full Code Here

  /**
   *
   */
  public void testIntSafeArray() {
    int sourceData[] = new int[] { 100000, 200000, 300000 };
    SafeArray saUnderTest = new SafeArray(Variant.VariantVariant, 3);
    saUnderTest.fromIntArray(sourceData);
    int[] extractedFromSafeArray = saUnderTest.toIntArray();
    for (int i = 0; i < extractedFromSafeArray.length; i++) {
      assertEquals("" + i, sourceData[i], extractedFromSafeArray[i]);
    }
    assertEquals("single get failed: ", sourceData[2], saUnderTest
        .getInt(2));

  }
View Full Code Here

  /**
   *
   */
  public void testLongSafeArray() {
    long sourceData[] = new long[] { 2L << 40, 3L << 41, 4L << 42 };
    SafeArray saUnderTest = new SafeArray(Variant.VariantVariant, 3);
    saUnderTest.fromLongArray(sourceData);
    long[] extractedFromSafeArray = saUnderTest.toLongArray();
    for (int i = 0; i < extractedFromSafeArray.length; i++) {
      assertEquals("" + i, sourceData[i], extractedFromSafeArray[i]);
    }
    assertEquals("single get failed: ", sourceData[2], saUnderTest
        .getLong(2));

  }
View Full Code Here

  /**
   *
   */
  public void testDoubleSafeArray() {
    double sourceData[] = new double[] { 1.5, 2.5, 3.5 };
    SafeArray saUnderTest = new SafeArray(Variant.VariantVariant, 3);
    saUnderTest.fromDoubleArray(sourceData);
    double[] extractedFromSafeArray = saUnderTest.toDoubleArray();
    for (int i = 0; i < extractedFromSafeArray.length; i++) {
      assertEquals("" + i, sourceData[i], extractedFromSafeArray[i]);
    }
    assertEquals("single get failed: ", sourceData[2], saUnderTest
        .getDouble(2));

  }
View Full Code Here

     * If option=0 (default) only the first selected item is returned.
     * If option=1 then all the selected items are returned delimited by |,
     * e.g: "0|3|4|10". If no items are selected a blank "" string is returned.
     */
    public String[] controlListViewGetSelectedArray(String title, String text, String control) {
        SafeArray safeArr = controlView(title, text, control, "GetSelected", "", "", "ControlListView").toSafeArray();
        return safeArr.toStringArray();
    }
View Full Code Here

     * @return Returns a 2 dimensional array containing the window titles
     * and corresponding handles.
     */
    public String[][] winList(String title, String text) {
        Variant result = winVariant(title, text, "WinList");
        SafeArray arr = result.toSafeArray();
        int entries = arr.getInt(0, 0);
        String[][] resultArr = new String[2][entries + 1];
        for (int i = 0; i <= entries; i++) {
            resultArr[0][i] = arr.getString(0, i);
            resultArr[1][i] = arr.getString(1, i);
        }
        return resultArr;
    }
View Full Code Here

     * @return Returns a 2 dimensional array containing the window titles
     * and corresponding handles.
     */
    public String[][] winList(String title) {
        Variant result = winVariant(title, "WinList");
        SafeArray arr = result.toSafeArray();
        int entries = arr.getInt(0, 0);
        String[][] resultArr = new String[2][entries + 1];
        for (int i = 0; i <= entries; i++) {
            resultArr[0][i] = arr.getString(0, i);
            resultArr[1][i] = arr.getString(1, i);
        }
       
        return resultArr;
    }
View Full Code Here

TOP

Related Classes of com.jacob.com.SafeArray

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.