paulohr
paulohr

Reputation: 586

Convert class from C++ to Delphi

I'm trying to convert a C++ project to Delphi, but I don't know how to convert these two classes:

class CData;
class CContext;

class CData
{
public:
    CContext* Data;
};

class CContext
{
public:
    char Unk[2240];
    DWORD data1;
    DWORD data2;
    DWORD data3;
};

Usage:

CData* Data = (CData*)(0x00112233);

//This code obtain the bytes in memory of the address "0x00112233" based on the sizes specified at CContext class

Please, if someone knows, help-me.

Thank you.

Upvotes: 2

Views: 174

Answers (2)

David Heffernan
David Heffernan

Reputation: 612794

The class is just a simple compound structure. That's a record in Delphi:

type
  TData = record
    unk: array [0..2240-1] of AnsiChar;
    data1, data2, data3: DWORD;
  end;

Your context type is just a pointer to that:

type
  TContext =^TData;

In the C code this pointer is wrapped in a class which seems a little pointless to me.

Declare a variable that is a pointer to TContext:

var
  context: ^TContext;

Assign it like this:

context := Pointer($00112233);

Upvotes: 6

Zac Howland
Zac Howland

Reputation: 15872

It looks like your CContext class is nothing more than a 2240 length string with 3 double-words of reserved space (likely that is never used). CData is nothing more than a pointer to an instance of CContext. To be more specific about how to port these, you would need to give more specifics on how they are used. As it stands right now, you could likely just implement a version of CData that has a string member.

Upvotes: 0

Related Questions