Solved

Convert C++ code to Delphi, please help!

Posted on 2006-07-18
4
340 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

733 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