Solved

Convert C++ code to Delphi, please help!

Posted on 2006-07-18
4
341 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
[X]
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
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

705 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