Solved

Convert C++ code to Delphi, please help!

Posted on 2006-07-18
4
334 Views
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!
0
Comment
Question by:Link-HRSystems
4 Comments
 
LVL 27

Assisted Solution

by:kretzschmar
kretzschmar earned 200 total points
ID: 17128668
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
 
LVL 12

Accepted Solution

by:
AmigoJack earned 300 total points
ID: 17128807
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
 
LVL 10

Expert Comment

by:atul_parmar
ID: 17128820
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
 

Author Comment

by:Link-HRSystems
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!
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
This video discusses moving either the default database or any database to a new volume.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 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

12 Experts available now in Live!

Get 1:1 Help Now