Translating a variable from C to Delphi

I am currently, not very successfully, attempting to convert some C files I was given to use in a Delphi application I am writing. I have never used C before but have found it easy to read and translate.
One area I am finding difficult to get to grips with is being able to distinguish between a variable which looks like a PChar but sometimes behaves like a dynamic array.

For Example the variable B:

C Code
------
EXTERN unsigned char  *A;
EXTERN unsigned char *B;
EXTERN unsigned smallint i,j;  

A := B
B[i + j] := 128

If A and B was a PChars in Delphi then A := B would be acceptable but the following line would require an array type which B is not.
If A was a PChar but B was an Array of Char then the first line would generate an error whereas the second line would not.

Could someone please tell me how this variable, B, should be defined in Delphi.

Thank you
RabsterAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
aikimarkConnect With a Mentor Commented:
From http://www.cpcug.org/user/clemenzi/technical/Languages/DataTypes.htm

it looks like your best bets for A,B definition are:
B: string;
B: ShortString;
B: AnsiString;  
0
 
RabsterAuthor Commented:
Aikimark,
Thanks for your comments. The data types sheet has enabled me to understand the differences in the language types.
Cheers
Rabster
0
 
robert_marquardtCommented:
Only Shortstring could work. string and AnsiString are definitely incompatible.

Use PChar for A and B. Signed vs unsigned is not that important.
You can always make your own type usable for [] in Delphi.

type
 PByte = ^ByteArray;
 ByteArray = array [0..MaxInt] of Byte;

A Pascal programmer calling C easily readable? You are definitely wierd ;-)
0
 
RabsterAuthor Commented:
I have tried creating a Byte Array previously. This is OK for the majority of my program until I hit the following as an example:

C Code
------
unsigned char *CFrom, *CTo;
EXTERN unsigned char *CAvg;

*To++ := Avg[(smallint)(228*(From[0]+From[1])+256)>>9];

My Delphi Code
--------------
var
  CFrom, CTo, CAvg : ByteArray;

CTo := CAvg[(228*(CFrom[0] + CFrom[1])+256) SHR 9];

PS
Have no idea what *To++:=, thought it may mean
To := To + in Delphi

PPS
You may be right about the weird thing.



0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.