Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified
Accepted Solution

Preprocessor Directives for JDE

Mike Kirkup briefly touched on the addition of pre-processor directives for the RAPC compiler during one of his presentations.

 

Although I took notes, I didn't get enough info from his presentation to actually get this working. Even worse, Mike's portion of the slide deck for this presentation (B08) did not get posted.

 

What we are trying to do is set up a 'define' statement and utilize #ifdef / #else / #endif to effect conditional compilation.

 

Can the RIM guys point us to some more detailed info?

 

 

 

 

Developer
marchywka
Posts: 1,415
Registered: ‎07-30-2008
My Device: Not Specified

Re: Preprocessor Directives for JDE

I don't know if you are interested but the c++ preprocessor works just fine and allows

generation of pure java code for other targets easily.  Not sure what RIM supports or possible benefits

but this works fine with cygwin,

 

g++ -x c++ $3 -I "$LAST_INC_PATH" $PKGFLAG -E "$1"

 

You need the "-x" option to get it to run the pp on java and the "-E" flag is to only do pp.

 

Retired
JWeber
Posts: 18
Registered: ‎07-14-2008
My Device: Not Specified

Re: Preprocessor Directives for JDE

Hello,

 

Thanks for pointing out that the slides didn't get posted, we are working at getting them added right now.

 

Here's some background information that should get you started.

 

Using the Pre-Processor in the JDE:

  • Preprocessor functionality is still present in previous versions, but does not have GUI support
  • Edit the .jdp file manually
    • Find the Options line
    • Add ‘–define <tag1>;<tag2>;…;<tagN>
    • e.g.: Options=-quiet
              -define= VER_4_2_0_AND_ABOVE;PREPROCESSOR
    • Note: The –define statement is an argument passed to rapc
  • Add directives as follows:

  //#preprocess

  public class Library implements LibraryInterface {
      public MenuItem[] getMenus() {
           MenuItem[] menuItems = null;

         

           //#ifdef VER_4_2_0_AND_ABOVE
           menuItems = new MenuItem[] { new InvokeAB(), InvokeMaps() };
           //#else
           menuItems = new MenuItem[] { new InvokeAB() };
           //#endif

 

           return menuItems;
 }

 

-Jeremy

 

 

 

Jeremy Weber
Sr Application Development Consultant
Research In Motion
Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Preprocessor Directives for JDE

Jeremy,

 

Thanks for the info.

 

I followed your instructions but still no joy.

 

I added the -define info in the jdp file:

 

Options=-quiet -define=JDE_4_5_0;PREPROCESSOR

 

I see the define statement on the rapc command line during compile.

 

C:\Program Files\Research In Motion\BlackBerry JDE 4.5.0\bin\rapc.exe  -quiet -define=JDE_4_5_0;PREPROCESSOR import="..\..\ 

 

The, I added the preprocess directive before the class definition:

 

//#preprocess

 

Then I added the preprocessor directives around the conditional code:

 

        //#ifdef JDE_4_5_0
          System.out.println("This is 4.5");
        //#else
          System.out.println("This is NOT 4.5");
        //#endif

My debug output looks like this:

 

This is 4.5
This is NOT 4.5

...which is not what I expected.

 

Did I miss a step?

 

 

 

Retired
JWeber
Posts: 18
Registered: ‎07-14-2008
My Device: Not Specified

Re: Preprocessor Directives for JDE

Try putting the "//#preprocess" line as the first line in the source file.  It appears that placing it elsewhere within the file doesn't invoke the preprocessing.

 

Jeremy Weber
Sr Application Development Consultant
Research In Motion
Developer
speedwagon
Posts: 21
Registered: ‎01-07-2009
My Device: Not Specified

Re: Preprocessor Directives for JDE

Sorry for bumping an old thread, but can anyone post a link to said presentation/slides?
Developer
marchywka
Posts: 1,415
Registered: ‎07-30-2008
My Device: Not Specified

Re: Preprocessor Directives for JDE

If you are going to bump this, let me comment on use of g++ preprocessor for this task as I've

had some good luck recently. As I mentioned before, I'm writing some B-tree code to replace

a data base. I need to test it and would like it to work on other phones too. I'm testing it on a desktop

using conditional compilation with tools already familiar. The conditional compilation is great

as I can just compile with things like "-DRIM_OS_TGT" or "-DEXCLUDE_RUNTIME_CHECKS" etc.

 

While I can't always get compiler error line numbers to work out ( I don't have right options probably ),

the runtime errors are automatic too as I have error handlers that look like

"error at "+__LINE__+" "+e.toString() that report to an internal status collector.

 

__DATE__ and __TIME__ etc and even #include work too.

New Developer
gbachmann
Posts: 3
Registered: ‎11-06-2008
My Device: Not Specified

Re: Preprocessor Directives for JDE

Bump for this thread, as it is not working right for me. I was at Mike Kirkup's presentation on the use of preprocessors. I've successfully used this in a JDE 4.7 project and code, but when I load the same code up in a JDE 4.2.1 project, the preprocessor define seems to be ignored. My notes from the session say that the preprocessor was supported on 4.0 and later?

 

I am putting the //#preprocess directive at the top of my source file

 

In my code, I have

 

//#ifdef  STUFF_FOR_JDE_47

...Storm-specific code goes here...

//#endif

 

When I build this in 4.7, works great. When I build this in 4.2.1, the compiler barfs on code inside of the #ifdef (such as touch objects). 

 

Any help appreciated!

Glenn

Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Preprocessor Directives for JDE

You also need to manually hack the JDP file to contain the pre-processor definition statement.

 

Something like this:

 

Options=-quiet -define=VERSION_4_2_1;PREPROCESSOR

New Developer
New Developer
rzr
Posts: 151
Registered: ‎01-05-2010
My Device: dev alpha c (bb10)

Re: Preprocessor Directives for JDE

[ Edited ]