Solved

Convert C++ FOR Loop to Delphi

Posted on 2012-04-12
2
526 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 26

Accepted Solution

by:
Sinisa Vuk earned 500 total points
ID: 37841400
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
ID: 37841843
Works sucessfully! Thank u..
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

856 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