Quote:Original post by Prototype
Trying to make assumptions about the binary layout of language-specific structures is not recommended, for example C++ doesn't mandate how classes should be implemented memory-wise (correct me if I'm wrong) so it may differ among compilers. A better way to share data would be to pass a pointer to an array of byte-encoded data, about which there can be no misunderstandings. Another idea is to write C-style wrapper code around your C++ objects, so it can easily be used from other languages. Hope this helps.
Well, so long as I use the same compiler all the time there shouldn't be a problem, however I see your point. Using structures (or similar) is faster than reading the whole thing byte by byte, though that would be possible and probably quite feasable if you wanted to read/write only one part of the data. It is of course a lot more convenient to be able to refer to a piece of data as something like 'Object.Array[3].SubObject.Property', than having to scan though the data and follow pointers, but you can't have everything I guess. Note that the data is being written by a separate application, so I only really have control over the Delphi side of things. I have been converting the C++ header files for loading the data, but have run into a wall with this.
Quote:Original post by Michalson
No, it's not.
You are comparing a stand alone data structure in C to a Object in Delphi. They are not the same.
The Delphi version of a struct is called a record
TStruct = record
dwProperty: DWORD;
end;
If you are using more then one member you might want to look into packed structs/records (if they are not packed, your compiler/settings will decide how best to space multiple members, which usually means they will be 32bit aligned).
So to review:
C++ Delphi
-----------------
int integer
{...} begin...end
struct record
class class
Well, kind of. Like I said, Delphi records appear to have the same internal data structure as C++ structures, but in C++ (or at least VC++) structures can have methods, and seem to be handled exactly like classes (I'm not a C++ guru). Also, as I said, I need circular references. Circular references with records would not work if it were actually allowed by the Delphi compiler (forward declarations of records are forbidden). The solution is to use classes.
I will look into the packed records thing, thanks.
I have found this article that seems to deal with the problem at hand. It would require me to persuade the C++ developer to change his program though. I am not very well grounded in C++ as I said, so if anyone could summarise what this would entail that'd be good (the C++ structures have a constructor and destructor, and no members).
http://rvelthuis.de/articles/articles-cppobjs.html
Thanks for your replied both.