[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 228
  • Last Modified:

Delphi to C++, please help me..

I have this code in delphi, but i need it for my c++ project. I dont know what functions are equivelant to c++, so can someone help? The variable Area is a 'pointer' in delphi, the mapSize is 'integer', the AreaFile is 'file'. The problem is that I dont know what the GetMem, AssignFile, etc etc functions are in c++. Can someone help me translate this code?? Thanks a lot!

  GetMem(Area, (mapSize + 1) * (mapSize + 1));
  AssignFile(AreaFile, MAPFILENAME);
  Reset(AreaFile, 1);
  BlockRead(AreaFile, Area^, mapSize * mapSize);
  CloseFile(AreaFile);

0
alkakios
Asked:
alkakios
  • 4
1 Solution
 
alkakiosAuthor Commented:
Somebody help pls!
0
 
robert_marquardtCommented:
This is plain C.

{
FILE *AreaFile;
char *Area;

Area = malloc((mapSize + 1) * (mapSize + 1));
AreaFile = fopen(MAPFILENAME, "rb");
fread(AreaFile, Area, mapSize, mapSize);
fclose(AreaFile);
}

Please have a look at the fread parameters. I may have mixed them up.
0
 
freshman3kCommented:
Hello!

Exactly what language you need to convert to

Borland c++ Builder
Borland c++ 5
Microsoft visual c++.... ?

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
alkakiosAuthor Commented:
Im using VC++6
And robert, thank you very much, i will try it now! (ill give u the points soon)
0
 
alkakiosAuthor Commented:
Oh, one more thing about arrays! I have a variable declaration in delphi like this: (2DArray)

LandData   : array[0..nofQuads - 1, 0..nofQuads - 1] of TQuad;

I try to do a 2d array in C++ like this:

TQuad*  LData;

LData = new TQuad[nofQuads-1][nofQuads-1];

but it shows me this error: error C2440: '=' : cannot convert from 'struct _TQuad (*)[8]' to 'struct _TQuad *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

Any ideas? the nofQuads is 8. i tried using 7 in the [][] but i still get the same error.
0
 
alkakiosAuthor Commented:
Oh, one more thing about arrays! I have a variable declaration in delphi like this: (2DArray)

LandData   : array[0..nofQuads - 1, 0..nofQuads - 1] of TQuad;

I try to do a 2d array in C++ like this:

TQuad*  LData;

LData = new TQuad[nofQuads-1][nofQuads-1];

but it shows me this error: error C2440: '=' : cannot convert from 'struct _TQuad (*)[8]' to 'struct _TQuad *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

Any ideas? the nofQuads is 8. i tried using 7 in the [][] but i still get the same error.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now