MikroC/MikroPascal Type Tanımlaması

Başlatan kartal0689, 11 Ağustos 2015, 09:07:26

kartal0689

Arkadaşlar,
MikroPascal ile yazılım yapıyorum. Fakat bilmediğim bir konu var. Type?
Aşağıdaki örnek kod ve help açıklamasında bu TYPE nasıl kullanılıyor?

type TOnEventPtr = procedure();

type TBytePtr = ^byte;

type TImage = record
  OwnerScreenAddress   : ^byte;
  Order                : byte;
  Left                 : word;
  Top                  : word;
  Width                : word;
  Height               : word;
  Picture_Name         : ^ const far byte;
  Visible              : byte;
  Active               : byte;
  Picture_Type         : byte;
  Picture_Ratio        : byte;
  OnUpPtr              : ^TOnEventPtr;
  OnDownPtr            : ^TOnEventPtr;
  OnClickPtr           : ^TOnEventPtr;
  OnPressPtr           : ^TOnEventPtr;
end;


Help Dosyasındaki açıklamalar;

Records
A record (analogous to a structure in some languages) represents a heterogeneous set of elements. Each element is called a field. The declaration of the record type specifies a name and type for each field. The syntax of a record type declaration is

type recordTypeName = record
 fieldList1 : type1;
  ...  fieldListn : typen;
end;


where recordTypeName is a valid identifier, each type denotes a type, and each fieldList is a valid identifier or a comma-delimited list of identifiers. The scope of a field identifier is limited to the record in which it occurs, so you don't have to worry about naming conflicts between field identifiers and other variables.

Note : In mikroPascal PRO for dsPIC30/33 and PIC24, you cannot use the record construction directly in variable declarations, i.e. without type.

For example, the following declaration creates a record type called TDot:
type  TDot = record    
  x, y : real;
end;


Each TDot contains two fields: x and y coordinates. Memory is allocated when you declare the record, like this:
var m, n: TDot;


This variable declaration creates two instances of TDot, called m and n.
A field can be of previously defined record type. For example:
// Structure defining a circle:
 type  TCircle = record    
 radius : real;
 center : TDot;
 end;


Accessing Fields
You can access the fields of a record by means of dot (.) as a direct field selector. If we have declared variables circle1 and circle2 of previously defined type TCircle:

var circle1, circle2 : TCircle;


we could access their individual fields like this:

circle1.radius := 3.7;
circle1.center.x := 0;
circle1.center.y := 0;


Accessing the fields is possible via the with statement as well.
You can also commit assignments between complex variables, if they are of the same type:

circle2 := circle1; // This will copy values of all fields