Convert C++ code to Delphi, please help!

Posted on 2006-07-18
Medium Priority
Last Modified: 2008-02-01
How do i convert the following C++ code to Delphi?

#define NIS_HIDDEN      0x00000001
#define NIS_SHAREDICON  0x00000002
unsigned        state = 0;
unsigned        statemask = 0;

if (statemask & state & NIS_HIDDEN)
     hidden = true;

if (statemask & state & NIS_SHAREDICON)
    shared = true;

Thanks for your help!
Question by:Link-HRSystems
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 27

Assisted Solution

kretzschmar earned 800 total points
ID: 17128668
hmm, i'm no c-coder but so i would it interpret

  NIS_HIDDEN  = 1;

  state : word := 0;
  statemask : word := 0;

hidden := statemask and state and NIS_HIDDEN;
shared := statemask and state and NIS_SHAREDICON;

i may wrong of course

meikl ;-)
LVL 12

Accepted Solution

AmigoJack earned 1200 total points
ID: 17128807
or try this

  NIS_HIDDEN      = $00000001
  NIS_SHAREDICON  =$00000002

  state, statemask: word;
  hidden, shared: boolean;

  state:= 0;
  statemask:= 0;

  // better set hidden and shared initially to sth
  hidden:= false;
  shared:= false;

  if (statemask and state and NIS_HIDDEN)<> 0 then hidden:= true;
  if (statemask and state and NIS_SHAREDICON)<> 0 then shared:= true;
LVL 10

Expert Comment

ID: 17128820
meik, almost correct except following
>>  state : word := 0;
>>  statemask : word := 0;
Variables can not be initialized where it is declared.
  state : word;   statemask : word;
  state := 0;
  statemask := 0;
>> hidden := statemask and state and NIS_HIDDEN;
>> shared := statemask and state and NIS_SHAREDICON;

hidden := (statemask and state and NIS_HIDDEN) > 0;
shared := (statemask and state and NIS_SHAREDICON) > 0;

  if (statemask and state and NIS_HIDDEN) > 0 then
    hidden := True;
  if (statemask and state and NIS_SHAREDICON) > 0 then
    shared := True;

Author Comment

ID: 17128841
Thank you all for the very quick response, it was the AND statement that completely confused me, i guess it is is doing a bitwise comparison?

I have split the points because Kretzschmar was nearly there, however AmigoJack gave the correct solution overall!

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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…
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 this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

801 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