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
New Contributor
amcgowanca
Posts: 5
Registered: ‎05-16-2010
My Device: BlackBerry Curve 8310

Eclipse and Preprocessing

Recently I have came accross a project which I am requiring to use preprocessor directives.

 

Here is my test code:

 

 

//#preprocess

package nextstop.ui;

import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.FullScreen;

public class Screen extends FullScreen
{
	public Screen()
	{
		super();
		
		//#ifdef PREPROCESS_CONST
		this.add( new LabelField("Hello World") );
		//#else
		this.add( new LabelField("Hello World - else statement") );
		//#endif
		
		//#ifndef PREPROCESS_CONST_TWO
		this.add( new LabelField("No Preprocess") );
		//#endif
	}
}

 

From this, with no preprocessor directives set I receive the all label fields being displayed including just the "Hello World" label. What is it that I am doing wrong here?

Developer
yyzTim
Posts: 304
Registered: ‎04-30-2008
My Device: Not Specified

Re: Eclipse and Preprocessing

I won't profess to be an expert but I recently had to do this so that I could have a version compiled at a higher level with additional functionality and it seemed to work fairly well.  I believe it makes a difference whether or not you are on the new plugin for Eclipse or the previous one which required as I understand it some manual edits to an ini file or something.  Assuming you are on the new plugin it seemed as easy as naming your constants after the default constant names Eclipse adds for each compiler level.

 

 

 

e.g.:  

 

//#ifdef BlackBerrySDK4.6.0

 

....

//#endif

New Contributor
jonesc
Posts: 6
Registered: ‎03-08-2010
My Device: BlackBerry Simulator

Re: Eclipse and Preprocessing

Do you try to move all //#xxxx preprocessor directives in the beginning of line?

It means no space or other characters in front of preprocessor directives.

New Contributor
amcgowanca
Posts: 5
Registered: ‎05-16-2010
My Device: BlackBerry Curve 8310

Re: Eclipse and Preprocessing

@yyzTim: Yes, I have new Eclipse plugin. Are you saying I can not define my own preprocessor constants and I am stuck with using the Eclipse defined ones? The reason I ask is because of the various versions of the app I am working along with a specific developer one that I am working on for testing in the field.

 

I have the new Eclipse plugin, defined and or undefined constants appropriately through.

- Project Properties > BlackBerry Project Properties > Compile ...

New Contributor
amcgowanca
Posts: 5
Registered: ‎05-16-2010
My Device: BlackBerry Curve 8310

Re: Eclipse and Preprocessing

@jonesc Yes, I have removed everything from the beginning of the file except //#preprocess which I have read and understood that it is required at the beginning of any file requiring preprocessing.

 

Any suggestions would be great?

New Contributor
amcgowanca
Posts: 5
Registered: ‎05-16-2010
My Device: BlackBerry Curve 8310

Re: Eclipse and Preprocessing

I have found a partial solution.

 

The solution that I have found is to add a default preprocessor directive to trigger the preprocessing. However, in my opinion is not the best. So, is there another way through Eclipse to automatically say that preprocessing must happen?

 

 

Developer
yyzTim
Posts: 304
Registered: ‎04-30-2008
My Device: Not Specified

Re: Eclipse and Preprocessing

Yes, that was the part that confused me a little.  I could add my own constants but I couldn't figure out how to triger them, that is why I went with the defaults.  I am sure there must be some way but I didn't look very hard because the defaults delivered exactly what I wanted.