Jak zamienić class z C++ na Delphi?

0

Czy ktoś umiałby to przetłumaczyć na Delphi:

// Klasa ID structure (64 bits total)
class CKlasaID
{
public:
    // Purpose: Constructor

    CKlasaID()
    {
        m_Klasaid.m_comp.m_unAccountID = 0;
        m_Klasaid.m_comp.m_EAccountType = k_EAccountTypeInvalid;
        m_Klasaid.m_comp.m_EUniverse = k_EUniverseInvalid;
        m_Klasaid.m_comp.m_unAccountInstance = 0;
    }

    // Purpose: Constructor
    // Input  : unAccountID -    32-bit account ID
    //            eUniverse -        Universe this account belongs to
    //            eAccountType -    Type of account

    CKlasaID( uint32 unAccountID, EUniverse eUniverse, EAccountType eAccountType )
    {
        Set( unAccountID, eUniverse, eAccountType );
    }

    CKlasaID( uint64 ulKlasaID )
    {
        SetFromUint64( ulKlasaID );
    }

    // Purpose: Sets parameters for Klasa ID
    // Input  : unAccountID -    32-bit account ID
    //            eUniverse -        Universe this account belongs to
    //            eAccountType -    Type of account

    void Set( uint32 unAccountID, EUniverse eUniverse, EAccountType eAccountType )
    {
        m_Klasaid.m_comp.m_unAccountID = unAccountID;
        m_Klasaid.m_comp.m_EUniverse = eUniverse;
        m_Klasaid.m_comp.m_EAccountType = eAccountType;
        m_Klasaid.m_comp.m_unAccountInstance = 0;
    }

    uint64 ConvertToUint64() const
    {
        return m_Klasaid.m_unAll64Bits;
    }


    // simple accessors
    void SetAccountID( uint32 unAccountID )        { m_Klasaid.m_comp.m_unAccountID = unAccountID; }


private:
    // These are defined here to prevent accidental implicit conversion of a u32AccountID to a CKlasaID.
    // If you get a compiler error about an ambiguous constructor/function then it may be because you're
    // passing a 32-bit int to a function that takes a CKlasaID. You should explicitly create the KlasaID
    // using the correct Universe and account Type/Instance values.
    CKlasaID( uint32 );
    CKlasaID( int32 );

    // 64 bits total
    union KlasaID_t
    {
        struct KlasaIDComponent_t
        {
            uint32                m_unAccountID : 32;            // unique account identifier
            unsigned int        m_unAccountInstance : 20;    // dynamic instance ID
            unsigned int        m_EAccountType : 4;            // type of account - can't show as EAccountType, due to signed / unsigned difference
            EUniverse            m_EUniverse : 8;    // universe this account belongs to
        } m_comp;

        uint64 m_unAll64Bits;
    } m_Klasaid;
};

dodanie znacznika <code class="cpp"> - fp

0

W zasadzie największy problem byłby chyba z tym:

        struct KlasaIDComponent_t
        {
            uint32                m_unAccountID : 32;            // unique account identifier
            unsigned int        m_unAccountInstance : 20;    // dynamic instance ID
            unsigned int        m_EAccountType : 4;            // type of account - can't show as EAccountType, due to signed / unsigned difference
            EUniverse            m_EUniverse : 8;    // universe this account belongs to
        } m_comp;

W Delphi nie ma bit fields (są natomiast we FPC), więc musiałbyś to albo symulować (http://stackoverflow.com/questions/282019/how-to-simulate-bit-fields-in-delphi-records), albo darować sobie pola bitowe i zrobić normalny rekord.
Reszta kodu jest dosyć prosta i byłoby łatwiej, gdybyś zadał konkretne pytanie.

0

@Arczibalek - a nawet jeśli ktoś by umiał, to co? Nie wiem czy wiesz, ale tutaj nie rozdajemy gotowców (przynajmniej co poniektórzy starają się), więc chcielibyśmy zobaczyć Twój wkład w translację; Inaczej to będzie wyglądać na proszenie o gotowca (i tak jest teraz);

Więc pokaż co udało Ci się przetłumaczyć (co już masz) i przede wszystkim napisz coś więcej na temat tego kawałka kodu;

A jeśli o tytuł wątku chodzi, to tak - w Object Pascalu (nie Delphi) także są klasy - trzeba tylko o tym wiedzieć, tak samo jak o ich obsłudze; Jeśli nie wiesz jak się posługiwać klasami to zobacz sobie do tego artykułu.

0

Tak dałem ogłoszenie bo sam nie daje rady i chętnie bym zapłacił za wiedze kogoś kto umiałby to zrobić, a potrzebuje to na wczoraj... :-(

1 użytkowników online, w tym zalogowanych: 0, gości: 1