Solved

Convert C++ FOR Loop to Delphi

Posted on 2012-04-12
2
516 Views
Last Modified: 2012-06-27
Hi guys,
I'm trying to convert a C++ FOR loop to Delphi, but I have no idea how to do it...

this is the C++ function:

bool bCompare(const BYTE* pData, const BYTE* bMask, const char* szMask)
{
    for(;*szMask;++szMask,++pData,++bMask)
        if(*szMask=='x' && *pData!=*bMask)   return 0;
    return (*szMask) == NULL;
}

Open in new window


I just got convert the function declaration:

function bCOmpare( pData: PBYTE; bMask: PBYTE; szMask: PCHAR):boolean;
begin
//...
end;

Open in new window


How is the conversion?

Thanks
0
Comment
Question by:Mascarado
2 Comments
 
LVL 25

Accepted Solution

by:
Sinisa Vuk earned 500 total points
Comment Utility
here it is:

function bCompare(pData: PBYTE; bMask: PBYTE; szMask: PChar): Boolean;
begin
  while (szMask^ <> #0) do
  begin
    if (szMask^ = 'x') and (pData^ <> bMask^) then
    begin
      Result := False;
      Exit;
    end;
    Inc(pData);
    Inc(bMask);
    Inc(szMask);
  end;

  Result := (szMask^ = #0);
end;

Open in new window

0
 

Author Closing Comment

by:Mascarado
Comment Utility
Works sucessfully! Thank u..
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now