• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 347
  • Last Modified:

Convert C++ code to Delphi, please help!

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!
0
Link-HRSystems
Asked:
Link-HRSystems
2 Solutions
 
kretzschmarCommented:
hmm, i'm no c-coder but so i would it interpret

const
  NIS_HIDDEN  = 1;
  NIS_SHAREDICON  = 2;

Var
  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 ;-)
0
 
AmigoJackCommented:
or try this

const
  NIS_HIDDEN      = $00000001
  NIS_SHAREDICON  =$00000002

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

begin
  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;
end;
0
 
atul_parmarCommented:
meik, almost correct except following
>>Var
>>  state : word := 0;
>>  statemask : word := 0;
Variables can not be initialized where it is declared.
Var
  state : word;   statemask : word;
begin
  state := 0;
  statemask := 0;
end
>> 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;

OR
  if (statemask and state and NIS_HIDDEN) > 0 then
    hidden := True;
  if (statemask and state and NIS_SHAREDICON) > 0 then
    shared := True;
0
 
Link-HRSystemsAuthor Commented:
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!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now