Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: API header declarations and inner classes


This question is answered. Helpful answers available: 1. Correct answers available: 1.


Permlink Replies: 4 - Last Post: Oct 12, 2017 11:20 AM Last Post By: Markus Humm
Markus Humm

Posts: 5,113
Registered: 11/9/03
API header declarations and inner classes  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 12, 2017 6:21 AM
Hello,

in some 3rd party SDK I shall use:
https://integrate.teamviewer.com/en/develop/screen-sharing-sdk/android-sdk-reference/

I stumbled upon the construct of inner classes. At least the TVSessionConfiguration
contains an inner class named TVSessionConfiguration.Builder.

How do I need to declare this in my API header translation unit?

Greetings

Markus
Dave Nottage

Posts: 1,850
Registered: 1/7/00
Re: API header declarations and inner classes  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 12, 2017 6:26 AM   in response to: Markus Humm in response to: Markus Humm
Markus Humm wrote:

I stumbled upon the construct of inner classes. At least the TVSessionConfiguration
contains an inner class named TVSessionConfiguration.Builder.

How do I need to declare this in my API header translation unit?

There's plenty of examples of similar use in the RTL, e.g. in Androidapi.JNI.Media:

  [JavaSignature('android/media/AudioAttributes$Builder')]
  JAudioAttributes_Builder = interface(JObject)
    ['{D73EC2B2-C044-4DF8-9190-64F781958EA9}']
    function build: JAudioAttributes; cdecl;
    function setContentType(contentType: Integer): JAudioAttributes_Builder; cdecl;
    function setFlags(flags: Integer): JAudioAttributes_Builder; cdecl;
    function setLegacyStreamType(streamType: Integer): JAudioAttributes_Builder; cdecl;
    function setUsage(usage: Integer): JAudioAttributes_Builder; cdecl;
  end;
  TJAudioAttributes_Builder = class(TJavaGenericImport<JAudioAttributes_BuilderClass, JAudioAttributes_Builder>) end;


Note the $ symbol used to denote that Builder is an inner class.

--
Dave Nottage [MVP, TeamB]
Find hints, tips and tricks at Delphi Worlds blog: http://www.delphiworlds.com
Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: API header declarations and inner classes  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 12, 2017 6:53 AM   in response to: Dave Nottage in response to: Dave Nottage

There's plenty of examples of similar use in the RTL, e.g. in Androidapi.JNI.Media:

  [JavaSignature('android/media/AudioAttributes$Builder')]
  JAudioAttributes_Builder = interface(JObject)
    ['{D73EC2B2-C044-4DF8-9190-64F781958EA9}']
    function build: JAudioAttributes; cdecl;
    function setContentType(contentType: Integer): JAudioAttributes_Builder; cdecl;
    function setFlags(flags: Integer): JAudioAttributes_Builder; cdecl;
    function setLegacyStreamType(streamType: Integer): JAudioAttributes_Builder; cdecl;
    function setUsage(usage: Integer): JAudioAttributes_Builder; cdecl;
  end;
  TJAudioAttributes_Builder = class(TJavaGenericImport<JAudioAttributes_BuilderClass, JAudioAttributes_Builder>) end;


Note the $ symbol used to denote that Builder is an inner class.

Hello,

I just learned that it's not an inner class but a nested class, and that seems
to be declared like a normal class. Am I right?

Greetings

Markus
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: API header declarations and inner classes
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 12, 2017 10:49 AM   in response to: Markus Humm in response to: Markus Humm
Markus Humm wrote:

How do I need to declare this in my API header translation unit?

If you look at Delphi's own Android units (the Androidapi.JNI.XXX.pas
units in the "$(BDS)\source\rtl\android" folder), many Android APIs use
inner classes.

In a nutshell, declaring an inner class is no different than declaring
its parent class. Declare the two classes separately (not nested), and
simply specify the full inner class name in the [JavaSignature]
attribute of the inner class.

For example, this is from Androidapi.JNI.Bluetooth.pas:

  // this is for the BluetoothClass parent class...
 
  Jbluetooth_BluetoothClassClass = interface(JObjectClass)
    ['{FF258AE0-A7F8-4869-B4F6-F061D1AE1264}']
    ...
  end;
 
  [JavaSignature('android/bluetooth/BluetoothClass')]
  Jbluetooth_BluetoothClass = interface(JObject)
    ['{5B43837A-0671-4D08-9885-EA58330D393E}']
    ...
  end;
  TJbluetooth_BluetoothClass =
class(TJavaGenericImport<Jbluetooth_BluetoothClassClass,
Jbluetooth_BluetoothClass>) end;
 
  // this is for the BluetoothClass.Device inner class...
 
  JBluetoothClass_DeviceClass = interface(JObjectClass)
    ['{38E343FC-1BF6-439D-96B5-C71B4B066930}']
    ...
  end;
 
  [JavaSignature('android/bluetooth/BluetoothClass$Device')]
  JBluetoothClass_Device = interface(JObject)
    ['{075C1041-C493-488E-A668-5D470339A25B}']
    ...
  end;
  TJBluetoothClass_Device =
class(TJavaGenericImport<JBluetoothClass_DeviceClass,
JBluetoothClass_Device>) end;


That being said, consider using Embarcadero's Java2OP tool to import
the 3rd parth SDK, don't translate it manually.

http://docwiki.embarcadero.com/RADStudio/en/Java2OP.exe,_the_Native_Bridge_File_Generator_for_Android

--
Remy Lebeau (TeamB)
Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: API header declarations and inner classes  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 12, 2017 11:20 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Am 12.10.2017 um 19:49 schrieb Remy Lebeau (TeamB):
Markus Humm wrote:

How do I need to declare this in my API header translation unit?

If you look at Delphi's own Android units (the Androidapi.JNI.XXX.pas
units in the "$(BDS)\source\rtl\android" folder), many Android APIs use
inner classes.

In a nutshell, declaring an inner class is no different than declaring
its parent class. Declare the two classes separately (not nested), and
simply specify the full inner class name in the [JavaSignature]
attribute of the inner class.

For example, this is from Androidapi.JNI.Bluetooth.pas:

  // this is for the BluetoothClass parent class...
 
  Jbluetooth_BluetoothClassClass = interface(JObjectClass)
    ['{FF258AE0-A7F8-4869-B4F6-F061D1AE1264}']
    ...
  end;
 
  [JavaSignature('android/bluetooth/BluetoothClass')]
  Jbluetooth_BluetoothClass = interface(JObject)
    ['{5B43837A-0671-4D08-9885-EA58330D393E}']
    ...
  end;
  TJbluetooth_BluetoothClass =
class(TJavaGenericImport<Jbluetooth_BluetoothClassClass,
Jbluetooth_BluetoothClass>) end;
 
  // this is for the BluetoothClass.Device inner class...
 
  JBluetoothClass_DeviceClass = interface(JObjectClass)
    ['{38E343FC-1BF6-439D-96B5-C71B4B066930}']
    ...
  end;
 
  [JavaSignature('android/bluetooth/BluetoothClass$Device')]
  JBluetoothClass_Device = interface(JObject)
    ['{075C1041-C493-488E-A668-5D470339A25B}']
    ...
  end;
  TJBluetoothClass_Device =
class(TJavaGenericImport<JBluetoothClass_DeviceClass,
JBluetoothClass_Device>) end;


That being said, consider using Embarcadero's Java2OP tool to import
the 3rd parth SDK, don't translate it manually.

http://docwiki.embarcadero.com/RADStudio/en/Java2OP.exe,_the_Native_Bridge_File_Generator_for_Android

Hello,

thanks to all of you, will try to find the time to check this tomorrow.

Greetings

Markus
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02