The following sample code illustrates how the API can be used.

 

You can use the predefined variable, CurrentProject, to access objects inside the current project.

 

You can query and/or manipulate retrieved objects (tables, queries, reports, labels, paper stocks).

 

You can query and/or manipulate retrieved objects from inside a report or label (components, parameters, computed fields, report sections, and DocumentInterface).

 

Retrieving tables

 

public boolean Report_Open() {

  …

  Table tables[] = CurrentProject.getTables( );

  // get table by name

  Table t1 = CurrentProject.getTable( "Fruits" );

  // JorderDetails is a Java Object added as a table

  Table t2 = CurrentProject.getTable( "JOrderDetails" );

  …

 

}

 

Retrieving queries

 

public boolean Report_Open() {

  …

  Query queries[] = CurrentProject.getQueries( );

  // get query by name

  Query q1 = CurrentProject.getQuery( "Query1" );

  …

 

}

 

Retrieving labels

 

public boolean Report_Open() {

  …

  Label labels[] = CurrentProject.getLabels( );

  // get label by name

  Label label1 = CurrentProject.getLabel ( "Label1" );

  …

 

}

 

Retrieving reports

 

public boolean Report_Open() {

  …

  Report reports[] = CurrentProject.getReports( );

  // get report by name

  Report r1 = CurrentProject.getReport( "Report1" );

  …

 

}

 

Retrieving paper stocks

 

public boolean Report_Open() {

  …

  PaperStock stocks[] = CurrentProject.getPaperStocks( );

  // get paper stock by name

  PaperStock stock1 = CurrentProject.getPaperStock( "Letter" );

  …

 

}

 

Querying and manipulating tables

 

public boolean Report_Open() {

  …

  // get table by name

  Table t1 = CurrentProject.getTable( "Fruits" );

  // get the name of the table

  String s1 = t1.getName();

  // JorderDetails is a Java Object added as a table

  Table t2 = CurrentProject.getTable( "JOrderDetails" );

  try {

     // setSourceObject and getSourceObject

     // only works with table added from Java Object.

     // OrderDetails is a class that contains

     // createOrderDetails method.

     // com.peernet.javaobject is package name, the user

     // can define your own package name.

     t2.setSourceObject( com.peernet.javaobject.OrderDetails.createOrdersDetails() );

  } catch (Exception e) {

     …

  }

 

  try {

     // setSourceObject must be called before calling

     // getSourceObject.

     // OrderDetails is a class that contains

     // createOrderDetails method.

     Object obj = t2.getSourceObject();

     // Description is an instance variable of OrderDetails

     String s2 = ((com.peernet.javaobject.OrderDetails)(((Vector)obj).firstElement()) ).Description;

  } catch (Exception e) {

     …

  }

 

  …

 

}

 

Querying queries

 

public boolean Report_Open() {

  …

  // get query by name

  Query q1 = CurrentProject.getQuery( "Query1" );

  // get the name of the query

  String s1 = q1.getName();

  …

 

}

 

Querying and manipulating labels

 

public boolean Report_Open() {

  …

  // get label by name

  Label labell = CurrentProject.getLabel ( "Label1" );

  // get the name of the label

  String s1 = label1.getName();

  label1.setBorderColor( new Color(255, 0, 0) );

  …

 

}

 

Querying and manipulating reports

 

public boolean Report_Open() {

  …

  Report reports[] = CurrentProject.getReports( );

  // get report by name

  Report r1 = CurrentProject.getReport( "Report1" );

  r1.setBorderColor( new Color(255, 0, 0) );

 

  // get all the parameters in this report

  Parameter params[] = getParameters( );

  // get all the computed fields in this report

  ComputedField computedFields[] = getComputedFields( );

  // get all the sections in this report

  Section sections[] = getSections( );

  // get all the components in this report

  Component components[] = getComponents( );

  // get component by name

  Component rect1 = getComponent( "Rectangle 2" );

  …

 

}

 

Querying paper stocks

 

public boolean Report_Open() {

  …

  PaperStock stocks[] = CurrentProject.getPaperStocks( );

  // get paper stock by name

  PaperStock stock1 = CurrentProject.getPaperStock( "Letter" );

  String s1 = stock1.getName();

  …

 

}

 

Querying and manipulating components (must include sub-report)

 

public boolean Report_Open() {

  …

  // get component by name

  Component rect1 = getComponent( "Rectangle 2" );

  String s1 = rect1.getName();

  rect1.setCanGrow( true );

  …

 

}

 

Querying parameters

 

public boolean Report_Open() {

  …

  // get all the parameters in this report

  Parameter params[] = getParameters( );

  String s1 = params[0].getName();

  …

 

}

 

Querying computed fields

 

public boolean Report_Open() {

  …

  // get all the computed fields in this report

  ComputedField computedFields[] = getComputedFields( );

  String s1 = computedFields[0].getName();

  …

 

}

 

Querying report sections

 

public boolean Report_Open() {

  …

  // get all the sections in this report

  Section sections[] = getSections( );

  String s1 = sections[0].getName();

  …

 

}

 

Querying and manipulating instance of DocumentInterface

 

public boolean Report_Open() {

  …

  Report reports[] = CurrentProject.getReports( );

  // get report by name

  Report r2 = CurrentProject.getReport( "Report2" );

 

  DocumentInterface documentInterface1;

  documentInterface1 = r2.format(null, null, null, null, null);

  int i = documentInterface1.getPageCount();

  …

 

}