- 2.2.18 -
TMT Pascal Language Description
Pascal Language StructureUser Defined Writer Procedure
TMT Pascal compiler allows one to define a writer procedure for ones own types
including objects and structures by means of the __writer reserved word.
The syntax of the custom writer procedure is the following:
procedure __writer (var f: text;
const value: <Custom Type>;
w: Integer);
begin
...
end;
The __writer example below showed the use of a
DateTime structure defined in the
DOS unit. A date is an ideal candidate for a Pascal
structure in which the data members (month, day, and year) are hidden from view.
An output file is the logical destination for displaying such a structure.
This code displays a date using the Write
procedure:
{$ifdef __GUI__}
uses DOS, WinCRT;
{$else}
uses DOS;
{$endif}
procedure GetCurrentDate(var date: DateTime);
var
Year, Month, Day, DayOfWeek: Word;
begin
GetDate(Year, Month, Day, DayOfWeek);
date.Year := Year;
date.Month := Month;
date.Day := Day;
end;
procedure __writer (var f: text;
const value: DateTime;
w: Integer);
begin
Write(f, value.Month, '/', value.Day, '/', value.Year);
end;
var
date: DateTime;
begin
GetCurrentDate(date);
Writeln(date);
end.
When you run this program, it prints the current date.
See also:
User Defined Reader Procedure
|
|
|
User Defined Reader Procedure |
Table of Content |
Built-in Assembler |
- 2.2.18 -