Board index » delphi » HELP: Can anyone translate this C++ code into Pascal/Delphi

HELP: Can anyone translate this C++ code into Pascal/Delphi

Can someone please help me with translating this C++ code into
Pascal/Delphi.

struct RARHeaderData
{
  char ArcName[260];
  char FileName[260];
  UINT Flags;
  UINT PackSize;
  UINT UnpSize;
  UINT HostOS;
  UINT FileCRC;
  UINT FileTime;
  UINT UnpVer;
  UINT Method;
  UINT FileAttr;
  char *CmtBuf;
  UINT CmtBufSize;
  UINT CmtSize;
  UINT CmtState;

Quote
};

struct RAROpenArchiveData
{
  char *ArcName;
  UINT OpenMode;
  UINT OpenResult;
  char *CmtBuf;
  UINT CmtBufSize;
  UINT CmtSize;
  UINT CmtState;

Quote
};

HANDLE PASCAL RAROpenArchive(struct RAROpenArchiveData *ArchiveData);
int PASCAL RARCloseArchive(HANDLE hArcData);
int PASCAL RARReadHeader(HANDLE hArcData,struct RARHeaderData
*HeaderData);
int PASCAL RARProcessFile(HANDLE hArcData,int Operation,char
*DestPath,char *DestName);
void PASCAL RARSetChangeVolProc(HANDLE hArcData,int
(*ChangeVolProc)(char *ArcName,int Mode));
void PASCAL RARSetProcessDataProc(HANDLE hArcData,int
(*ProcessDataProc)(unsigned char *Addr,int Size));
void PASCAL RARSetPassword(HANDLE hArcData,char *Password);

Thanks.

        Petter  ( pett...@online.no )

 

Re:HELP: Can anyone translate this C++ code into Pascal/Delphi


Take a look at the source code in Windows.pas, which lists the Delphi
version for the nearly all of the windows API, and compare with the native
C code version of the Windows API, to see how Borland did the translations.
 Then just follow Borland's examples.  Good luck.
Gene

Beetle <bee...@stealthmail.com> wrote in article
<346F5A9B.A5654...@stealthmail.com>...

Quote
> Can someone please help me with translating this C++ code into
> Pascal/Delphi.

> struct RARHeaderData
> {
>   char ArcName[260];
>   char FileName[260];
>   UINT Flags;
>   UINT PackSize;
>   UINT UnpSize;
>   UINT HostOS;
>   UINT FileCRC;
>   UINT FileTime;
>   UINT UnpVer;
>   UINT Method;
>   UINT FileAttr;
>   char *CmtBuf;
>   UINT CmtBufSize;
>   UINT CmtSize;
>   UINT CmtState;
> };

> struct RAROpenArchiveData
> {
>   char *ArcName;
>   UINT OpenMode;
>   UINT OpenResult;
>   char *CmtBuf;
>   UINT CmtBufSize;
>   UINT CmtSize;
>   UINT CmtState;
> };

> HANDLE PASCAL RAROpenArchive(struct RAROpenArchiveData *ArchiveData);
> int PASCAL RARCloseArchive(HANDLE hArcData);
> int PASCAL RARReadHeader(HANDLE hArcData,struct RARHeaderData
> *HeaderData);
> int PASCAL RARProcessFile(HANDLE hArcData,int Operation,char
> *DestPath,char *DestName);
> void PASCAL RARSetChangeVolProc(HANDLE hArcData,int
> (*ChangeVolProc)(char *ArcName,int Mode));
> void PASCAL RARSetProcessDataProc(HANDLE hArcData,int
> (*ProcessDataProc)(unsigned char *Addr,int Size));
> void PASCAL RARSetPassword(HANDLE hArcData,char *Password);

> Thanks.

>    Petter  ( pett...@online.no )

Re:HELP: Can anyone translate this C++ code into Pascal/Delphi


I'm not sure what you are asking exactly.  If you want to know what a
struct is in Delphi/pascal then the answer is: in Pascal, a struct is a
record and would be declared thusly (keep in mind that, while C is case
sensitive, Pascal is not):

TYPE
        RARHeaderDataRec = RECORD
                arcname: string[250];
                flags: UINT; //see windows.pas
                ...
        end;

var
        RARHeaderData : RARHeaderDataRec;

If you have Delphi, I believe one of the manuals has some help on pascal
conventions.  Your local library might help.  And searching on the
internet for converting C to Pascal might help.

Ok, now we are getting to the hairy stuff because I have never had an
easy time going from handles in C to handles in Pascal.  I get a headache
every time I have to deal with this. But I would guess the easiest way to
do it would be to remind oneself that a handle is just a pointer to a
pointer.  Most important, Pascal demands that pointers be the same base
type as the type of data that they point to. This is a pain but
prevents some sloppy errors that can easily occur in C which doesn't
have such rigid type checks. Thus:

type
        RAROpenArchiveDataRec = Record
                .
                .
        end;
        RAROpenArchiveDataPtr = ^RAROpenArchiveDataRec;
        RAROpenArchiveDataHandle = ^RAROpenArchiveDataPtr;
        //pascal ^ is like C asterisk
and
        int PASCAL RARCloseArchive(HANDLE hArcData);
would become
        function RARCloseArchive                        
              (hArcData:RAROpenArchiveDataHandle);integer;pascal;

I haven't tested any of this.  It is all off the top of my head. I hope I
haven't steered you in the wrong direction. Be aware that the pascal
directive at the end of the function declaration is saying that it
expects arguments to be on the stack in a certain order.  Make sure,
before using this directive, that it is really want you want.  

In article <01bcf2f5$524eda60$0390a8c0@svr_theta>, ge...@mindspring.com
says...

Quote
> Take a look at the source code in Windows.pas, which lists the Delphi
> version for the nearly all of the windows API, and compare with the native
> C code version of the Windows API, to see how Borland did the translations.
>  Then just follow Borland's examples.  Good luck.
> Gene

> Beetle <bee...@stealthmail.com> wrote in article
> <346F5A9B.A5654...@stealthmail.com>...
> > Can someone please help me with translating this C++ code into
> > Pascal/Delphi.

> > struct RARHeaderData
> > {
> >   char ArcName[260];
> >   char FileName[260];
> >   UINT Flags;
> >   UINT PackSize;
> >   UINT UnpSize;
> >   UINT HostOS;
> >   UINT FileCRC;
> >   UINT FileTime;
> >   UINT UnpVer;
> >   UINT Method;
> >   UINT FileAttr;
> >   char *CmtBuf;
> >   UINT CmtBufSize;
> >   UINT CmtSize;
> >   UINT CmtState;
> > };

> > struct RAROpenArchiveData
> > {
> >   char *ArcName;
> >   UINT OpenMode;
> >   UINT OpenResult;
> >   char *CmtBuf;
> >   UINT CmtBufSize;
> >   UINT CmtSize;
> >   UINT CmtState;
> > };

> > HANDLE PASCAL RAROpenArchive(struct RAROpenArchiveData *ArchiveData);
> > int PASCAL RARCloseArchive(HANDLE hArcData);
> > int PASCAL RARReadHeader(HANDLE hArcData,struct RARHeaderData
> > *HeaderData);
> > int PASCAL RARProcessFile(HANDLE hArcData,int Operation,char
> > *DestPath,char *DestName);

Other Threads