C++ into Delphi

Is there anyone who can translate these C++ code into Delphi ?

BYTE *BuildCommandReply(int comid, int nReplyCode, char *svReply, int *pnReqLen)
{
      BYTE *buffer;
      struct bo_command_header *hdr;
      int buflen,nReplyLen;
      
      buflen=sizeof(struct bo_command_header) + sizeof(int);
      nReplyLen=0;
      if(svReply!=NULL) {
            nReplyLen = (lstrlen(svReply)+1);
            buflen += nReplyLen;
      }
      

      buffer=(BYTE *) malloc(buflen);
      if(buffer==NULL) {
            *pnReqLen=0;
            return NULL;
      }
      memset(buffer,0,buflen);

      hdr=(struct bo_command_header *)buffer;      

      hdr->cmdlen=buflen;
      hdr->comid=comid;
      hdr->command=-1;
      hdr->flags=CMDFLAG_REPLY;
      hdr->nArg1=nReplyCode;
      hdr->nArg2Len=nReplyLen;
      hdr->nArg3Len=0;
      if(svReply!=NULL) {
            lstrcpyn((char *)buffer+sizeof(struct bo_command_header),svReply,nReplyLen);
      }

      *pnReqLen=buflen;            
      return buffer;
}
zekoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AttarSoftwareCommented:
type
  pByte = ^byte
  pLongint = ^longint ;
  pBo_Command_Header = ^tBo_Command_Header ;

function BuildCommandReply( comid, nReplyCode : longint ; svReply : pChar ; pnReqLen : pLongint ) : pByte ;
var
  buffer : pByte ;
  hdr : pBo_Command_Header ;
  buflen,nReplyLen : longint ;
begin
  buflen := sizeof( tBo_command_header ) + sizeof( longint ) ;
  nReplyLen := 0 ;
  if( svReply <> nil ) then
  begin
    nReplyLen := ( strlen( svReply ) + 1 ) ;
    Inc( bufLen, nReplyLen ) ;
  end ;

  buffer := allocMem( buflen ) ;
  if( buffer = nil ) then
  begin
    pnReqLen^ = 0 ;
    result := nil ;
    exit ;
  end ;

  FillChar( buffer^, buflen, #0 ) ;

  hdr := pBo_command_header( buffer ) ;

  hdr^.cmdlen := buflen;
  hdr^.comid := comid;
  hdr^.command := -1;
  hdr^.flags := CMDFLAG_REPLY;
  hdr^.nArg1 := nReplyCode;
  hdr^.nArg2Len := nReplyLen;
  hdr^.nArg3Len := 0;
  if( svReply <> nil ) then
    CopyMemory( pointer( longint( buffer ) + sizeof( tBo_command_header ) ), svReply, nReplyLen ) ;

  pnReqLen^ := buflen ;
  result := buffer ;
end ;

Or something like that (I havent tried compiling this as you ae missing the tBo_Command_Header structure...)

Good luck...

Tim :O)

PS:  Got to be worth 50 points at least?
0
zekoAuthor Commented:
Post me an answer, Attar Software .
0
AttarSoftwareCommented:
Woohoo :)

Thanks :)

Tim.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.