<div dir="auto"><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Amir via fpc-devel <<a href="mailto:fpc-devel@lists.freepascal.org">fpc-devel@lists.freepascal.org</a>> schrieb am Do., 5. Dez. 2024, 00:57:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><u></u>
<div> I wonder why? Is there any technical difference between classes
and records for the purpose of forward declaration?<br></div></blockquote></div></div><div dir="auto"><br></div><div dir="auto">Yes, there is. Classes are implicit pointer types, thus when you have a field that is of type class then it's size will always be the size of a Pointer. Records (and TP-style objects) have a different size depending in their fields and this size needs to be known when you use a record (or TP-style object) directly as a field. </div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>
<br>
My use-case was to define a few records like the following:<br>
<br>
type<br>
TData = record<br>
....<br>
function ToA: TA;<br>
end;<br>
<br>
TA = record<br>
Data: TData;<br>
....<br>
end;<br>
<br>
I know I can define classes instead of record, but I do not want to
do so, since I need to "Free" the objects.<br></div></blockquote></div></div><div dir="auto"><br></div><div dir="auto">You could add a record helper below the declaration of TA for TData instead of declaring ToA inside of TData:</div><div dir="auto"><br></div><div dir="auto">=== code begin ===</div><div dir="auto"><br></div><div dir="auto"> TDataHelper = record helper for TData</div><div dir="auto"> function ToA: TA;</div><div dir="auto"> end;</div><div dir="auto"><br></div><div dir="auto">=== code end ===</div><div dir="auto"><br></div><div dir="auto">The usage is the same as if you had declared the method inside of TData. </div><div dir="auto"><br></div><div dir="auto">Regards, </div><div dir="auto">Sven </div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div></div>
</blockquote></div></div></div>