Microsoft KB Archive/71277

How to Return Record Types from Unit Functions in Pascal PSS ID Number: Q71277 Article last modified on 04-16-1991 PSS database name: S_PasCal

3.32 4.00 | 3.32 4.00

MS-DOS | OS/2

Summary:

When creating a function within a unit that returns a record type, you must export the record definition; otherwise, the record will have a local scope and it will not be recognized outside of the unit.

This information applies to Microsoft Pascal versions 3.32 and 4.00 for MS-DOS and MS OS/2.

More Information:

The following code illustrates the proper way to return the record type from within the unit:

CMPLX.INC (This is the interface of the unit.)
interface; unit cmplx(i, complex); type complex = record {This definition must be exported in } re : real; {the ‘unit’ section above. } im : real; end; function i : complex; end;

CMPLX.PAS (This is the implementation of the unit.)
{$include: ‘CMPLX.INT’} implementation of cmplx; function i; begin i.re := 0; i.im := 1; end; end.

PROG.PAS (This is the main program that uses the unit.)
{$include: ‘CMPLX.INT’} program prog; uses cmplx; var cnum : complex; begin cnum := i; end.

Copyright Microsoft Corporation 1991.