[fpc-pascal] Type helper for JNI pointers
Benito van der Zander
benito at benibela.de
Sun Aug 12 13:42:10 CEST 2018
Hi,
when you use JNI functions you always need to repeat "env" a lot:
var
javaClass: jclass;
javaObj: jobject;
begin
//javaClass := ...
javaObj := env^^.NewObject(env, javaClass)
env^^.DeleteLocalRef(env, javaObj);
end;
So I thought you could declare type helpers for jobject and jclass,
TjobjectHelper = type helper for jobject
procedure DeleteLocalRef;
end;
TjclassHelper = type helper for jclass
procedure NewObject;
end;
And then just write
var
javaClass: jclass;
javaObj: jobject;
begin
//javaClass := ...
javaObj := javaClass.NewObject()
javaObj.DeleteLocalRef;
end;
But this does not work, because fpc thinks jclass and jobject are the
same type, so there is only one type helper for both of the types allowed.
Because it is declared as
type
jobject=pointer;
jclass=jobject;
What can we do about this?
Bye,
Benito
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20180812/d7fac963/attachment.html>
More information about the fpc-pascal
mailing list