[fpc-devel] Converting records back and forth. (Forward declarations for records needed ?!?)
Hans-Peter Diettrich
DrDiettrich1 at aol.com
Tue Sep 20 15:10:16 CEST 2011
Skybuck Flying schrieb:
> Hello,
>
> I want to write code as follows and I will simplify it here to illustrate
> the problem.
>
> Let's say I want to kinds of records: TrecordA and TrecordB.
>
> I want to be able to convert types of TrecordA to TrecordB but I also want
> to be able to convert types of TrecordB to TrecordA.
>
> So I was thinking of writing code as follows:
>
> type
> TrecordA = record
> function ToRecordB : TrecordB;
> end;
>
> TrecordB = record
> function ToRecordA : TrecordA;
> end;
That's the wrong way. You should pass in an parameter of the output
type, allocated by the caller. Then pass it as a pointer, and declare
the pointer types before the records.
DoDi
More information about the fpc-devel
mailing list