Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How defince a C++ Data Structure in Delphi

Posted on 1999-06-25
11
Medium Priority
?
314 Views
Last Modified: 2010-04-06
I would like to call a Function written by C++ and with a
data structure parameter. How should I define a related
data structure in Delphi?
0
Comment
Question by:jaygibb
[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
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1384695
It would be easier if you post the C++ structure you need convert, then we can show you how it should look in Delphi.

I assume you are calling a DLL? Or is it a COM/ActiveX object?

Cheers,

Raymond.

0
 

Author Comment

by:jaygibb
ID: 1384696
in C program

typedef struct{
uchar

0
 

Author Comment

by:jaygibb
ID: 1384697
in C program

typedef struct{
uchar timeout1;
uchar timeout2;
uchar timeout3;
uchar timeout4;
} PRRAMETERS;
0
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!

 
LVL 20

Expert Comment

by:Madshi
ID: 1384698
In Delphi this should look like this:

type TParameters = packed record
                     timeout1, timeout2, timeout3, timeout4 : byte;
                   end;

Or even this one:

type TParameters = array [1..4] of byte;

Regards, Madshi.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1384699
Generally you should convert such structures in packed records...
0
 
LVL 15

Expert Comment

by:simonet
ID: 1384700
>PRRAMETERS

type
 PRRAMETERS = ^TParameters;

(just my 2 cents! since Madshi's already said everything!)

Alex
0
 

Author Comment

by:jaygibb
ID: 1384701
type StrucName=packed record
 ..;
 ..;
end;

why is there a key word 'packed' here?

Is that necessary?

0
 
LVL 20

Expert Comment

by:Madshi
ID: 1384702
Hi Alex, hmm, it is really a pointer in C? I don't see any "*" or something like that? Ok, I'm no real C expert...   :-)

JayGibb, normally Delphi's records are 4-byte aligned. That means, without the keyword packet, the record would we look like this:

type TParameters = packed record
                     timeout1 : byte;  // memory offset 0
                    [unused space : 3 bytes]
                     timeout2 : byte;  // memory offset 4
                    [unused space : 3 bytes]
                     timeout3 : byte;  // memory offset 8
                    [unused space : 3 bytes]
                     timeout4 : byte;  // memory offset 12
                   end;

This way the executable runs slightly faster, since the CPU is faster with 4-byte aligned variables.

AFAIK, in C(++) you can do the same, but you must have to set a specific pragma for that. Normally C(++)'s records are not aligned. That's a bit slower, but it consumes less memory.

To get a compatible record in Delphi you need to use the packed keyword.

Type "packed" into your Delphi editor and press F1. Then you'll read what Borland has to say about it...

Regards, Madshi.
0
 
LVL 15

Expert Comment

by:simonet
ID: 1384703
You're right again, Madshi.
0
 
LVL 20

Accepted Solution

by:
Madshi earned 100 total points
ID: 1384704
That's nice...   :-)

So I guess, I can answer this question.

Regards, Madshi.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1384705
Jaygibb? Are you there?
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

662 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