Mikroelektronika MIKROE-742 데이터 시트

다운로드
페이지 532
Example
Here’s an example procedure which transforms its input time parameters, preparing
them for output on Lcd:
procedure time_prep(var sec, min, hr : byte);
begin
sec  := ((sec 
and $F0) shr 4)*10 + (sec and $0F);
min  := ((min 
and $F0) shr 4)*10 + (min and $0F);
hr   := ((hr  
and $F0) shr 4)*10 + (hr  and $0F);
end;
A function can return a complex type. Follow the example bellow to learn how to
declare and use a function which returns a complex type.
Example: 
This example shows how to declare a function which returns a complex type.
program Example;
type TCircle = record
// Record
CenterX, CenterY: word;
Radius: byte;
end;
var MyCircle: TCircle; // Global variable
function DefineCircle(x, y: word; r: byte): TCircle; // DefineCircle
function returns a Record
begin
result.CenterX := x;
result.CenterY := y;
result.Radius  := r;
end;
begin
MyCircle := DefineCircle(100, 200, 30);                      //
Get a Record via function call
MyCircle.CenterX := DefineCircle(100, 200, 30).CenterX + 20; //
Access a Record field via function call
//                  |-----------------------|  |-----|
//                     |                         |
//                  Function returns TCircle     Access to one
field of TCircle
end. 
141
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Language Reference
mikroPASCAL PRO for AVR
CHAPTER 5