Solved

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

Posted on 2007-03-30
5
992 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
[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
  • 2
  • 2
5 Comments
 
LVL 101

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

Industry Leaders: 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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month3 days, 11 hours left to enroll

630 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