Solved

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

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

828 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