Solved

How can I convert c++ struct to pascal code?

Posted on 2007-03-30
5
982 Views
Last Modified: 2008-01-09
Here is C++ struct code declaration:

      struct HLIST
      {
            char         Index;
            int            No:8 ,  Count:24;
            __int64    Offset;                              
      };


I don't know how can I convert bit declaration;;

Here is my code:

      THLIST = packed record
            Index: BYTE;
                No_Count: Integer;  //   int            No:8 ,  Count:24;
            Offset: Int64
      };

I try to declare whole 32bit data(No 8bit, Count 24bit = Total 32bit) to Integer type!!
Then get No and Count value by bit operation!!

 No = THList.No_Count and $000F;
 Count = THList.No_Count and $FFF0;


Is there any convert way gracefully to access each `No` and `Count` variables in record!!
0
Comment
Question by:byungho
  • 2
  • 2
5 Comments
 
LVL 100

Expert Comment

by:mlmcc
ID: 18824209
Actually the record has 2 integer components.  Try

      THLIST = packed record
            Index: BYTE;
                No   :    Integer;
                Count: Integer;  //   int            No:8 ,  Count:24;
            Offset: Int64
      };

mlmcc
0
 
LVL 11

Accepted Solution

by:
robert_marquardt earned 125 total points
ID: 18824694
mlmcc is wrong (even with his credentials). Two integers do not work.
The struct is converted correctly. The only question is if it is really packed.
The only way to declare No and Count separately in Delphi is

      THLIST = packed record
            Index: Shortint;
            No: Shortint;
            Count: array [0..2] of Byte;
            Offset: Int64;
      end;

It does not really help you though. It is awkward to get the value of Count into a real Integer.
BTW Index is signed so Shortint is better. Alternatively use Char.
0
 

Author Comment

by:byungho
ID: 18825461
robert!! yes it packed!!  I want to access two variables separately!!

So is it impossible to convert pascal code? -_-;;; It is not easy to use!
0
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 18827670
The above gives you separate variables, but you will have to copy the 3 byte value to an Integer and also have to sign-extend it yourself. It therefore only helps you for "No". Write some access functions.
0
 

Author Comment

by:byungho
ID: 18827876
Thank you for reply~~ I'll try~
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

707 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

11 Experts available now in Live!

Get 1:1 Help Now