I am trying to access Java classes dynamically from *.apk file using C++ Builder (Android development). For this purpose I have found complete guide with example in Delphi (here: http://www.pclviewer.com/android/androidJNI.html). Everything works fine in Delphi, but when I tried to rewrite Pascal source code (at the end of guide) into C++ using C++ Builder XE7, I found curious problem. How to cast Delphi interface into TObject* in C++, properly invoke ClassName() function and get JavaObjectID? I spent a lot of time, but still cannot rewrite these 3 lines of code:
var
JavaObject:JObject;
oTemp:TObject;
JavaObjectID:JNIObject;
:
oTemp:=JavaObject as TObject; //1. ?
JavaObjectID:=tjavaimport(otemp).GetObjectID; //2. ?
memo1.Lines.Add(oTemp.ClassName); //3. ?
:
I have tried differenet type casts, also using GetInterface() method of TObject class, but nothing works. As a C++ programmer I don't understand how is it possible directly cast delphi interface into TObject*.
Androidapi::Jni::Javatypes::_di_JObject JavaObject;
System::TObject* oTemp;
Androidapi::Jni::_JNIObject *JavaObjectID;
:
oTemp = (TObject*)(&JavaObject); //Compiling ok, but segmentation fault
?
Memo1->Lines->Add(oTemp->ClassName()); // after ClassName() invoke.
Does anybody know. how to rewrite these 3 lines of Pascal code into C++ please? Thank you very much for your response.
TObject
. Isn't that something that you should not do? – David HeffernanClassName
is a method ofTObject
. A Delphi interface may be implemented by an instance of a class, and theas
cast is a way to retrieve that implementing instance. Of course, some interfaces are external and are not implemented by Delphi objects. For them, theas
cast will fail. – David Heffernan