Solved

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

Posted on 2007-03-30
5
984 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

863 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

21 Experts available now in Live!

Get 1:1 Help Now