Archived

This topic is now archived and is closed to further replies.

What's this in Delphi?

This topic is 5619 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey there! I''m trying to translate a little helper routine from C++ to Delphi. It basically calculates the bit-shifts for the different color modes when plotting pixels on a DirectDraw surface. Anyway, here''s what it looks like:
  
void ProcessBits( DWORD Mask, WORD* LowBit, WORD* NumBits )
{
   DWORD TestMask = 1;
   for( *LowBit = 0; *LowBit < 32; ( *LowBit )++ )
   {
      if( Mask & TestMask )
         break;
      TestMask <<= 1;
   }

   TestMask <<= 1;
   for( *NumBits = 1; *NumBits < 32; ( *NumBits )++ )
   {
      if( !( Mask & TestMask ))
         break;
      TestMask <<= 1;
   }
}
  
The problem is this line: if( Mask & TestMask ) break; because Mask and TestMask a Word values and if Mask and Test Mask then Break; gives me an error (obviously), because the return value is not a boolean. Any idea how I could work around this?

Share this post


Link to post
Share on other sites
Bung a comparison with 0 into there:

if (Mask and TestMask) <> 0 then
Rejoice;


Any ''if'' statements in C++ that rely on the values 0 or non-zero for false or true should be converted this way (with the appropriate sign, ''='' or ''<>''.

Share this post


Link to post
Share on other sites
You could use:


if WordBool(Mask and TestMask) then Break;

or

if Mask and TestMask<>0 then Break;

(If you are using Professional or Enterprise these should both compile to exactly the same code, I''m not sure about Personal but its likely).

Share this post


Link to post
Share on other sites