Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You misunderstood what those C structs represent. That's because a <code>record</code> is a value type: it's stored right there where you declare the variable. So let's do a few levels of recursive declarations, and you'll understand what I mean; Assuming the two structures aren't absolutely identical:</p> <pre><code>type TA = record test1 : TB; SomethingElseFromA: Byte; end; TB = record test2 : TA; SomethingElseFromB: Byte; end; </code></pre> <p>Structure <code>TA</code> could be rewritten to mean this:</p> <pre><code>type TA = record // Replaced test1 : TB with the actual content of TB, because that's // what a record means. test1_test2: TA; test1_SomethingElseFromB: Byte; SomethingElseFromA: Byte; end; </code></pre> <p>Of course, we've now got a nice recursive inclusion of self into the <code>TA</code> record, something along the lines of:</p> <pre><code> TA = record // Replaces test1_test: TA test1_test2: TA; // Oops, still not fixed, need to do it again... test1_SomethingElseFromB: Byte; SomethingElseFromA: Byte; test1_SomethingElseFromB: Byte; SomethingElseFromA: Byte; end; </code></pre> <p>You probably want to use reference types to get something that looks similar, but it's not similar. A reference type is always a pointer, so it's a fixed size; The compiler can allocate it without a problem. This would be valid, using pointers-to-records:</p> <pre><code>type pTypeB = ^typeB; pTypeA = ^typeA; typeA = record test1 : pTypeB; end; typeB = record test2 : pTypeA; end; </code></pre> <p>Alternatively you could use classes; That works for the same reason, classes are reference types; they work the same way as pointers. When you declare a variable of pointer-type, the compiler allocates <code>SizeOf(Pointer)</code> bytes.</p> <hr> <p>Since you've posted the C structs, I can tell they're too long for me to attempt a complete translation, but I can make a few suggestions: You should declare all your types in a single <code>Type</code> block; don't write the <code>Type</code> before each type declaration. This allows you to create the pointer type before the record type, like this:</p> <pre><code>Type PMyRecord = ^TMyRecord; // Somewhere in the same Type block TMyRecord = record end; </code></pre> <p>For each type that requires pointers-to-records, declare the pointers first thing after the <code>Type</code> keyword, it's simpler that way. Next, you need to identify the C pointers. If there's a <code>*</code> between the name of the data type and the name of the field, that's a pointer. This is usually written like this:</p> <pre><code>int *PointerToSomeInt; </code></pre> <p>But those would be just as valid:</p> <pre><code>int * PointerToSomeInt; int* VarName1, * VarName1, * VarName3; // Three pointers to integer. </code></pre> <p>Finally, you'll need to deal with alignment issues. If you can, check the size of the structures on the C side, and then check the size on the Delphi side: you should get the same size. If you don't, you should try a couple of random <code>{$ALIGN}</code> compiler directives before your structure declaration and repeat until you strike the correct alignment. If all else fails you'll need to find what's wrong (what fields are aligned differently on the Delphi side) and put in some alignment bytes to artificially fix it.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload