Reduce number of class files produced by BlackBerry app - blackberry

I have developed an order processing application for BlackBerry. When I look at the bin folder I see more than 100 .class files.
I have created a main screen class for adding new clients. The screen has 7 LabelField objects and 7 corresponding TextField objects. This screen also creates a VerticalFieldManager and adds all these fields to it and then adds the VerticalFieldManager to the screen.
For this screen, I have 14 .class files in the bin folder. It seems there is one class file for every field in the progam.
For example:
NewClient.class
NewClient$1.class
...
NewClient$14.class
How do I design the UI in order to reduce the number of compiled classes?

Building a Java-ME app for BlackBerry is a two step process. First the java source code is compiled to class files, then those class files are compiled again into a .cod file, which can be deployed onto a simulator or a device.
'rapc' is the RIM compiler that takes java programs and turns them into a cod or alx file for deployment. 'rapc' can take either java source code, or compiled java classes. Either way, it can produce output suitable for a device.
When starting with Java source files, you can explicitly compile them to class files and hand those class files to rapc or you can pass the Java source to rapc and it will compile the source directly. rapc just defers to the JDK javac compiler when presented with java source code. This means a standard java JDK compiler is always used as the first step of compiling a BlackBerry app, and we can look at standard java behavior to understand what is happening.
In Java, every class that is instantiated has exactly one .class file. For normal classes with a declared name, like this:
public class Foo extends Bar {
}
The .class file is assigned a name that matches the declared class name. However, Java also allows anonymous classes. These take the form of a new Foo() followed by a curly brace which turns this into an anonymous class. This presents a problem, as this anonymous class must be assigned a name at the VM level, despite having none at the Java source level. The solution is to use a character that is invalid in Java source, but valid in the VM, namely $. The anonymous classes are assigned a name based on the enclosing Java class, followed by $, then an integer index based on the number of anonymous classes ahead of this one. In your case, that is NewClient, followed by 14 distinct integers.
To see the behavior you describe, your fields must all actually be anonymous implementations of those classes you mention. To reduce the number of classes, try reusing explicit classes, instead of writing custom behavior with each instantiation.

Set your jdk bin folder path on the environment variable path on right clicking on the myComputer icon
Then Restart the pc
Other way is to don't use overwrite method on your code such as
btmSave.setChangeListner(new FieldChangeListner()
{
private void fieldChange()
{
}
}
);
Avoid This type of writing code it create your no of class Files on project bin folder

Related

Why is this Groovy AST transformation within a Grails app only being applied during class reloading?

In an attempt to develop a global AST transformation to add a new method to an Enum class within my app, I've set up this example project using Grails 5.
https://github.com/davebrown1975/grails_enum_experiment
The expected behaviour is that on compilation/building, the AST transform will be applied to the single enum class in the project ('tst.ExampleEnum'). I can see the 'visit' method being called in my Transformer ('tst.EnumTranslationTransformation'), however the sourceunit ast classes passed as a parameter to the visit method never include my Enum class.
Once the app is running however, if I make the simplest change to the Enum class, e.g. pressing space somewhere and saving it to trigger compilation and reloading, then this time I will see output in the console informing me the visit method was called AND the enum class was detected and AST has been applied.
Things I've tried, as per Grails docs, established the transforming class in it's own 'plugin', putting the class into a sub package of org.grails.compiler. Neither of these made a difference and I didn't see the AST being called at ever until I referenced the EnumTranslatorTransformation class from within a new file META-INF/services/org.codehaus.groovy.transform.ASTTransformation
Any thoughts as to what I'm missing here would be greatly appreciated.
The solution I found that ensures the AST is compiled and applied to the Enums at build time was to place the transformation into an inline plugin. What was critical at this point was to ensure that the META-INF/services/org.codehaus.groovy.transform.ASTTransformation file was moved to the plugin and not the main app. Only then would I see the transformation applied after a clean and build of the project.

What its the first, the annotated class (egg) or used class (chicken)?

certainly I have not read something fundamental, and it seems very strange, but I wonder.
Suppose you use
#SharedPref
public interface SharedPreferencesInterface {
#DefaultBoolean(true)
boolean showDeviceName();
I have the IDE (idea) configured with Gradle, and I generated the SharedPreferencesInterface_ class that I can use in another class as
#Pref
SharedPreferencesInterface_ prefs;
But suppose someone now download the project, how can the use? Because the class where used SharedPreferencesInterface_ not compile because the class does not exist, and the class does not exist because compilation errors ...
How it's made? Surely there is a way ... configured to compile certain classes first?
Help is appreciated.
A greeting.
But suppose someone now download the project, how can the use? Because
the class where used SharedPreferencesInterface_ not compile because
the class does not exist, and the class does not exist because
compilation errors ...
This is the same situation when you compile a project in a full build (when no classes are generated yet). Actually Gradle always does a full build currently in Android projects. No configuration is needed at all in addition to the standard AndroidAnnotaions config.
Actually this works because the compiler does not fully compiles your class before passing it to annotations processing. It is clear it should not to, because the class may reference generated classes, which are only available after the processing. So first the compiler creates a model of the classes, only parses the structure of the them (fields, methods, return types, parameter types, etc), but not the implementations. Also it allows missing types even on fields. If it finds a missing type, it assigns to TypeKind.ERROR, but the name of the type is still available for the annotation processor. After the processor is done, it generates the missing class, so the kind of the class is no longer TypeKind.ERROR, and the compilation can succeed.

Delphi classes registered in package A not found in package B

After some research i decided to word the question differently:
I have an application and 2 packages (BaseClasses and ClassImplementations).
BaseClasses is loaded by way of having a unit in the application uses clause:
uses
BaseClasses;
ClassImplementations is loaded by way of LoadPackages:
LoadPackage("classImplementations.bpl");
From my application i call my parser, located in BaseClasses:
Parser.Parse(txt)
When calling code in my base classes, i have an "is" condition, checking if an implementation class IS a certain base class.
if classImpl is BaseClass then
This condition returns false.
If however i load my ClassImplementations package by way of having it in my application uses clause, that same condition returns true:
uses
BaseClasses, ClassImplementations;
This means that classes registered in package ClassImplementations are not available in package BaseClasses.
The application uses runtime packages, containing rtl and vcl. I see that the initialization section, containing my registerclass method in classImplementations is called and that it does find the class i need in the application, but not in the BaseClasses package
What am i missing?
Check your dependencies. The second package "classImplementations.bpl" needs to have the first one in its requires clause.
Also, the main executable project needs to have the first package listed in its runtime package list in project options.

How can I get a list of classes defined in my project at run time?

I want to load all classes from a current project in a TList. If I read the dpr file like a normal file it will return me only strings. I want to get all the classes defined in the dpr file and their names. Does someone know how to do that?
In the Delphi IDE, all classes are available in the .dcu files, corresponding to each .pas files. Those .dcu files have a proprietary binary evolving format, so can not be used outside the IDE.
At program execution, and within the exe file, there is no list of all existing classes. You can retrieve information about a known class using the RTTI functions (see TypInfo.pas and relatives as stated by the Embarcadero documentation). So at runtime, you just can retrieve information from a given class: you can use e.g. anObject.ClassName or anObject.ClassType methods.
But I suspect you want to retrieve all classes defined in a project, from its source code. For this, you will need a source code parser, which will extract the logic from the .pas files. In short, the parser will read the .dpr then all necessary .pas files source code, interpret the object pascal type definitions, and create a list of units, classes, methods and properties. There are several parsers around: see for instance PasDoc or the version we embedded in SynProject.
Additional note - for an exhaustive list: If you generate a .map file during the compilation, this text file will contain all symbol names of the executable, including the classes. You'll have to parse it, but won't have much information to deal with, since there is no easy way of guessing if each symbol is a class or a record, for instance, or about classes inheritances or properties... This .map is intended about execution debugging, not RTTI.

Delphi, can't use a function in an external .pas file

I am using functions from an external .pas file. I can use some of the functions, but not others. As far as i can see the functions are declared the same way, I would like to post some of the file, but don't know ho to post large amounts of code.
You can use the functions that are declared in the interface section, that is the section of code before the implementation section.
You are probably trying to call functions that are defined only in the implementation section, that is that code that appears after the implementation keyword.
These different sections are how Delphi implements public and private visibility at the unit level.
Usually, in well written units, there will be a reason for functions being made private to the unit. But if you feel it reasonable to override the author's decision then you need to redeclare the function in the interface section. This will make it available to your code which uses the 3rd party unit.
The file is not properly linked and/or not included in your projects search path and/or shadowed by some other file with same function names and/or odd functions are within $IFDEF clauses.
Check spelling, uses clauses, working function location (Ctrl+click on function name in your code), $IFDEF clauses.
The file is not properly linked in Delphi environment options
The file could be located outside of project search path. Hence it's not linked.
The file path is typed wrongly in project (DPR file). E.g. you are referring to older path with olde version of a file.
In each of these cases some functions could be taken from other files if name fits. E.g. function gluUnproject can be taken both from OpenGL.pas and dglOpenGL.pas, if first unit is not linked properly I would get the same problem as you are having now - some functions work and some are missing. In any of the cases you should compile your project, Ctrl+Click on a working function name and see where it brings you, check file version location.
The functions could be inside of $IFDEF clauses. These are compiler directives and code within such clause will be invisible to compiler if certain condition is not met. E.g. {$IFDEF MSWindows} Func {$ENDIF} won't be accessible on Linux.

Resources