* pas2jni: Removed option to create event handler by passing Java method method name as a string. It is not safe, since the target method is treated as unused by Java and the method may be removed from the resulting application.

git-svn-id: trunk@34367 -
This commit is contained in:
yury 2016-08-22 10:13:45 +00:00
parent 385f13cae9
commit e81cc4574f
2 changed files with 7 additions and 24 deletions

View File

@ -33,11 +33,12 @@ The following Pascal features are supported by pas2jni:
- pointer type;
- string types;
- all numeric types;
- method pointer.
- method pointer;
- setters/getters for array elements.
USUPPORTED features:
- array;
- procedure pointer.
- Full support for arrays;
- procedure pointer (Not possible to implement. To workaround this limitation create a procedure handler in your Pascal code and call a method pointer declared in some global Pascal class. Then you can assign this method pointer from a Java code).
Shared libraries, generated by pas2jni were tested with Java on Windows and Android. It should work on other systems as well.
@ -84,9 +85,7 @@ In a Java code you get the following TMyClass instance:
TMyClass myclass = TMyClass.Create();
It is possible set a Java handler in 2 ways:
1) Place the handler inline.
Then you add the event handler in a usual Java way:
...
myclass.setOnChange(
@ -98,21 +97,6 @@ It is possible set a Java handler in 2 ways:
);
...
2) Define the handler as a method in a class.
public class MyJavaClass {
private void DoOnChange(TObject Sender) {
// The handler code
}
public void main() {
...
// Set the handler to the method with the "DoOnChange" name in the current class (this).
myclass.setOnChange( new TNotifyEvent(this, "DoOnChange") );
...
}
}
COMMAND LINE OPTIONS
Usage: pas2jni [options] <unit> [<unit2> <unit3> ...]

View File

@ -1433,13 +1433,12 @@ begin
Fjs.WriteLn(Format('/* Pascal prototype: %s */', [GetProcDeclaration(d, 'Execute')]));
Fjs.WriteLn(Format('/* Java prototype: %s */', [GetJavaProcDeclaration(d, 'Execute')]));
Fjs.WriteLn(Format('public static class %s extends %s.system.MethodPtr {', [d.Name, JavaPackage]));
Fjs.WriteLn(Format('public static abstract class %s extends %s.system.MethodPtr {', [d.Name, JavaPackage]));
Fjs.IncI;
Fjs.WriteLn(Format('{ mSignature = "%s"; }', [GetProcSignature(d)]));
Fjs.WriteLn(Format('protected %s(long objptr, boolean cleanup) { _pasobj=objptr; }', [d.Name]));
Fjs.WriteLn(Format('public %s(Object Obj, String MethodName) { mObject=Obj; mName=MethodName; }', [d.Name]));
Fjs.WriteLn(Format('public %s() { mObject=this; mName="Execute"; }', [d.Name]));
Fjs.WriteLn(Format('protected %s throws NoSuchMethodException { throw new NoSuchMethodException(); }', [GetJavaProcDeclaration(d, 'Execute')]));
Fjs.WriteLn(Format('protected abstract %s;', [GetJavaProcDeclaration(d, 'Execute')]));
Fjs.DecI;
Fjs.WriteLn('}');
Fjs.WriteLn;