I have two types. One Type A and one Type B. The Problem Type A contains Type B and Type B contains Type A. Such a thing like this won’t work:
type
typeA = record
test1 : typeB;
end;
type
typeB = record
test2 : typeA;
end;
Edit:
Thats not my design. I converting C Header files (to access a DLL) that include such constructs to delphi.
Edit2:
“C++ structs are another name for classes AFAIR. And there must have been pointers, not values themselves. – Arioch ‘The 1 min ago”
Yes you are right that was a Pointer to a Type:
There I definied:
test1 : ^typeB;
Will that work instead?
test1 : Pointer;
Edit3:
The C Structs:
/* DLPDFPAGE */
typedef struct dlpdfpage
{
CosObj Page;
CosObj PrintSelect;
ASFixedRect PageBBox;
ASFixedRect ContentBBox;
struct dlpdfpage *Next;
PDRotate Angle;
struct dlpdfdoc *Doc;
DLPDFSTREAM *Content;
long PageNumber;
char Complete;
char FontSubstituted;
char FontMM;
char FontBad;
} DLPDFPAGE;
/* DLPDFDOC */
typedef struct dlpdfdoc
{
DLPDFINSTANCE *dliInstance;
PDDoc pdDoc;
CosDoc cosDoc;
DLPDFOUTLINE *Outlines;
char *PDFFileName;
char *PDFPostFileName;
DLPOS LastPageEnd;
DLPOS BeforeDef;
ASFixedRect DocBBox;
long PageCount;
long PageTreeWidth;
long PageTreeDepth;
long PageTreeDepthUsed;
DLPDFPAGETREEARRAY *AllPages;
DLPDFFONTLIST *AllFonts;
DLPDFFORMLIST *AllForms;
DLPDFFORMLIST *AllColors;
DLPDFIMAGELIST *AllImages;
DLPDFSPOTCOLORLIST *AllSpotColors;
DLPDFSPOTCOLORLIST *AllPatterns;
DLPDFEXTGSTATELIST *AllExtGStates;
DLPDFPAGE *PageList;
DLPDFPAGE *LastPage;
DLPDFDEST *DeferedDests;
DLPDFSIGNATURE *signatureHolder;
struct dlpdfacroform *AcroFormBase;
CosObj PatternColorObj,
PatternColorRGBObj,
PatternColorCMYKObj,
PatternColorGrayObj,
PrintSelect,
PrintSelectCriteria;
CosObj IdentH, IdentV;
ASAtom DocumentEncoding;
long FontCount;
long FormCount;
long PatCount;
long ImageCount;
char Compress;
char Linearize;
char PageTreeComplete;
char EmbedFonts;
char PatternColorsDefined;
char MakeThumbNails;
ASBool psSevenBitSafe;
ASInt32 EncryptKeyByteCount;
char condenseResDicts;
CosObj resourceDict;
ASInt16 pdfMajorVer;
ASInt16 pdfMinorVer;
DLPDFINCLUDEDRES *InclRes;
DLPDFSPOTCOLORLIST *AllShadings;
long ShadeCount;
} DLPDFDOC;
You misunderstood what those C structs represent. That’s because a
recordis 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:Structure
TAcould be rewritten to mean this:Of course, we’ve now got a nice recursive inclusion of self into the
TArecord, something along the lines of: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:
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
SizeOf(Pointer)bytes.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
Typeblock; don’t write theTypebefore each type declaration. This allows you to create the pointer type before the record type, like this:For each type that requires pointers-to-records, declare the pointers first thing after the
Typekeyword, it’s simpler that way. Next, you need to identify the C pointers. If there’s a*between the name of the data type and the name of the field, that’s a pointer. This is usually written like this:But those would be just as valid:
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
{$ALIGN}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.