在DELPHI中创建枚举

时间:2015-03-13 09:20:43

标签: java delphi enums

我在JAVA中有一个枚举代码。我将所有JAVA代码转换为DELPHI。

我快完成了,但是我坚持到了这里。我不知道,如何将枚举转换为Delphi。

我想知道,这段代码可以转换为Delphi吗?

   /**
     * Enum describing the databin class ID's. Methods exist for getting the
     * KakaduClassID and the StandardClassID. I have also included the string
     * representations of the databins as defined for cache model updates.
     * 
     * 
     */
    public enum JPIPDatabinClass {

        /** Precinct data bin class. */
        PRECINCT_DATABIN(KakaduConstants.KDU_PRECINCT_DATABIN, JPIPConstants.PRECINCT_DATA_BIN_CLASS, "P"),

        /** Tile Header data bin class. */
        TILE_HEADER_DATABIN(KakaduConstants.KDU_TILE_HEADER_DATABIN, JPIPConstants.TILE_HEADER_DATA_BIN_CLASS, "H"),

        /** Tile data bin class. */
        TILE_DATABIN(KakaduConstants.KDU_TILE_DATABIN, JPIPConstants.TILE_DATA_BIN_CLASS, "T"),

        /** Main Header data bin class. */
        MAIN_HEADER_DATABIN(KakaduConstants.KDU_MAIN_HEADER_DATABIN, JPIPConstants.MAIN_HEADER_DATA_BIN_CLASS, "Hm"),

        /** Meta data bin class. */
        META_DATABIN(KakaduConstants.KDU_META_DATABIN, JPIPConstants.META_DATA_BIN_CLASS, "M");

        /** The classID as an integer as per the Kakadu library. */
        private int kakaduClassID;

        /** The classID as an integer as per the JPEG2000 Part-9 standard. */
        private int standardClassID;

        /**
         * The classID as a string as per the JPEG2000 Part-9 standard. Used for
         * cache model updates.
         */
        private String jpipString;

        /**
         * Constructor.
         * 
         * @param _kakaduClassID
         * @param _standardClassID
         * @param _jpipString
         */
        JPIPDatabinClass(int _kakaduClassID, int _standardClassID, String _jpipString) {
            kakaduClassID = _kakaduClassID;
            standardClassID = _standardClassID;
            jpipString = _jpipString;
        }

        /** Returns the classID as an integer as per the Kakadu library. */
        public int getKakaduClassID() {
            return kakaduClassID;
        }

        /** Returns the classID as an integer as per the JPEG2000 Part-9 standard. */
        public int getStandardClassID() {
            return standardClassID;
        }

        /**
         * Returns the classID as a string as per the JPEG2000 Part-9 standard. Used
         * for cache model updates.
         */
        public String getJpipString() {
            return jpipString;
        }

    };

1 个答案:

答案 0 :(得分:4)

这个Enum很容易被翻译成一个普通的旧Delphi类,它有一个像Java Enum这样的三参数构造函数,以及三个只读的公共属性。

JPIPDatabinClass = class(TObject)
private
  ...
public
  constructor Create(AKakaduClassID: Integer; AStandardClassID: Integer; AJPIP: string);

  property KakaduClassID: Integer; read FKakaduClassID;
  property StandardClassID: Integer; read FStandardClassID;
  property JPIP: string; read FJPIP;
end;

和'singleton style'实例:

function PRECINCT_DATABIN: JPIPDatabinClass;
function TILE_HEADER_DATABIN: JPIPDatabinClass;
...

implementation

var
  FPRECINCT_DATABIN: JPIPDatabinClass;
  FTILE_HEADER_DATABIN: JPIPDatabinClass;
...
  FPRECINCT_DATABIN := JPIPDatabinClass.Create( ... );
  FTILE_HEADER_DATABIN := JPIPDatabinClass.Create( ... );
...  

function PRECINCT_DATABIN: JPIPDatabinClass;
begin
  Result := FPRECINCT_DATABIN;
end;

function TILE_HEADER_DATABIN: JPIPDatabinClass;
begin
  Result := FTILE_HEADER_DATABIN;
end;
...

注意:这种方法的缺点是不能创建真正的Delphi枚举类型,它只将Java枚举类型模拟为不可变的Delphi对象。