aspose file tools*
The moose likes Java in General and the fly likes Java data type compatible to record in Delphi Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java data type compatible to record in Delphi" Watch "Java data type compatible to record in Delphi" New topic
Author

Java data type compatible to record in Delphi

Saurabh Bhandarkar
Greenhorn

Joined: Jan 17, 2011
Posts: 4

Hi all,
I am writing code for calling dll functions from java. I am using JNA (Java native access) library for it.
There is one function in DLL which takes Delphi record (just like structure in C) as argument.
For this I created a class having attributes same as that of in delphi record & passed its object as argument
while calling that DLL function.But I am getting java.lang.IllegalArgumentException.

I understand that a C like structure in java is nothing but a class itself. But is there any other type or class
from Java collection similar to record in Delphi?

Thanks.

Regards,
Saurabh
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19722
    
  20

Can you show us the Delphi record definition and its matching definition in Java?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Saurabh Bhandarkar
Greenhorn

Joined: Jan 17, 2011
Posts: 4

Hi Rob,
here is the Delphi record definition

TSHREEDATA = RECORD
SHREE_ERROR : BYTE;
SHREE_ACTIVE : BYTE;
CURSCR : BYTE;
FONTNAME : ARRAY[0..LF_FACESIZE] OF BYTE;
FONTSIZE : LONGINT;
FONTATTR : BYTE;
FONTLAYOUT : BYTE;
ACTIVATIONKEY : BYTE;
HYPHENATION_ON : BYTE;
KEYBOARDNAME : ARRAY[0..12] OF BYTE;
END;

and similar java class

public class shreeRec {
public byte SHREE_ERROR;
public byte SHREE_ACTIVE;
public byte CURSCR;
public byte FONTNAME[];
public int FONTSIZE;
public byte FONTATTR;
public byte FONTLAYOUT;
public byte ACTIVATIONKEY;
public byte ACTIVATIONKEY_ON;
public byte KEYBOARDNAME[];
}
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19722
    
  20

You don't initialize your arrays. They remain null. What happens if you initialize them?
Also, I'm not that familiar with JNA, but shouldn't your class extend Structure or whatever the class is called?

I wasn't sure if Delphi's longint maps to Java's int. I'd have guessed long is a better match. I've checked and it has the same bounds, so that's a good choice after all.
Saurabh Bhandarkar
Greenhorn

Joined: Jan 17, 2011
Posts: 4

Thanks for the reply Rob.

While using JNA we need to write an interface which declares all the functions in the dll & this interface extends the Library class of JNA.
I am able to call & execute other functions in dll using JNA...no problem about that.
I am stuck only at the Record-Class issue.
Also,I initialized the arrays & changed int to longint.But still the same exception is coming.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19722
    
  20

Rob Prime wrote:Also, I'm not that familiar with JNA, but shouldn't your class extend Structure or whatever the class is called?

From the JNA docs of com.sun.jna.Structure:
Represents a native structure with a Java peer class. When used as a function parameter or return value, this class corresponds to struct*. When used as a field within another Structure, it corresponds to struct. The tagging interfaces Structure.ByReference and Structure.ByValue may be used to alter the default behavior.

So what happens if you let your shreeRec class extend Structure (and implement Structure.ByValue if needed)?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java data type compatible to record in Delphi