How To Use Fpc
TypeMyObject = ObjectfInteger: integer;fString: ansiString;fArray: array 1.3 of char;end;In the above example, the Pascal keyword record has been replaced with the keyword object. Objects are more useful when method fields are added to the object. Object methods are declared in FPC using the keywords procedure or function and are declared the same way as normal Pascal procedures and functions only that they are declared within the scope of the object declaration itself.

Before attempting to open an FPC file, you'll need to determine what kind of file you are dealing with and whether it is even possible to open or view the file format. Answer: Files which are given the.FPC extension are known as Catalog files, however other file types may also use this extension.
A more useful object declaration (as part of an example graphics application) is shown below. TypeDrawingObject = Objectx, y: single;height, width: single;procedure Draw;end;VarRectangle: DrawingObject;In addition to the single precision floating point data fields, the object shown above declares a method; a procedure called Draw. Following the 'DrawingObject' type declaration is a variable declaration: Rectangle of the type DrawingObject. Next, the Draw procedural code itself needs to be written as well as well as code for accessing and manipulating the data fields. The Draw procedure is written separately outside of the DrawingObject declaration.
Where this Procedure declaration is written is not specified and depends on your particular coding standards.The following simple program shows how all this works. It should compile and run on any system with FPC 2.2.2 and above. Note: For Mac OS X, the -macpas compiler directive must be turned off. Program TestObjects;TypeDrawingObject = Objectx, y: single;height, width: single;procedure Draw; // procedure declared in hereend;procedure DrawingObject.Draw;beginwriteln('Drawing an Object');writeln(' x = ', x, ' y = ', y); // object fieldswriteln(' width = ', width);writeln(' height = ', height);writeln;// moveto (x, y); // probably would need to include a platform dependent drawing unit to do actual drawing//. TypeTShape = Objectx, y: single;height, width: single;procedure GetParams;procedure Draw;end;TRectangle = Object(TShape)procedure Draw;end;TSquare = Object(TRectangle)procedure GetParams;procedure Draw;end;VarShape: TShape;Rectangle: TRectangle;Square: TSquare;Notice that TRectangle lists only the Draw procedure while TSquare lists both the GetParams and Draw procedures. Neither of the subobject types include any fields.
The 'missing' fields and missing procedure names are said to be inherited from the fields and procedures declared in ancestor objects. In this case, any object variables declared and instantiated of type TRectangle will inherit from the TShape type all four fields, (x, y, height, and width) and the GetParams method. At runtime, a variable of the type TRectangle will look and behave like a TShape variable except that the Draw procedure will use different code than the procedure by the same name in an instantiated variable of the TShape type. Similarly, the TSquare object type will inherit all the 'grandparent' fields from TShape and have its own different procedure blocks. If desired, TRectangle and TSquare could have declared additional fields in their type definitions which would show up as additional fields (memory locations) available at runtime which instantiated parent object variables would not have or be able to access.Next are the specific procedure implementations for these object types.

For k:= 1 to Numshapes doShapek.draw;Where each Shape object could be one of any sub objects descended from TShape. Code maintenance is made easier since there is one fewer locations in code which needs to be modified. All changes to the behavior of a particular sub object of shape is kept together in one place.Virtual KeywordHowever, as seen in the last section, calling the Draw method for the Shape variable this way will not invoke the appropriate draw method of the sub object which is the behavior that is desired in this (and most) cases. To obtain the desired behavior, the virtual keyword must be inserted after the method declaration in the type definition as follows. TypeTShape = Objectx, y: single;height, width: single;procedure GetParams;procedure Draw; virtual;end;TRectangle = Object(TShape)procedure Draw; virtual;end;Now if a Rectangle object is assigned to the Shape variable, the Draw method of TRectangle will be used. The term often used to describe this situation is called overriding a parent method.
How To Use Focus Mitts
Although the body of main program will the same as in the previous section, the execution behavior will be different. The virtual keyword tells the compiler to hold off fixing the specific procedure used and instead lets the binding of the method be determined at runtime dynamically.By adding the virtual keyword to the type declarations of TShape, TRectangle and TSquare in the last section, the latter portion of the output would look as shown below. Note that in order to run the previous program using virtual methods, some other code needs to be added in order for the program to run. This additional code is described in the next section.Assigning Rectangle to ShapeCalling Shape.Draw: TRectangle.DrawAssigning Square to ShapeCalling Shape.Draw: TSquare.DrawAssigning Square to RectangleCalling Rectangle.Draw: TSquare.DrawAlthough it is allowed, mixing virtual methods and non virtual (static) methods in the inheritance hierarchy may result in behavior which is difficult to manage.Objects - Constructors and DestructorsCompiling the above example program after adding the virtual keywords will result in non fatal compiler warnings about missing constructors. Although the warnings can be ignored, a run time error will almost certainly occur when one of the virtual Draw methods is executed. Due to the peculiarities of this particular OOP implementation, when virtual methods are declared, special initialization code must be included for that object. Specifically, two specialized methods must be included in the object type definition called a constructor and a destructor.
The constructor must be called at runtime to initialize the object's virtual method before the method is called. In addition, the constructor can be (and should) be used to initialize any fields, dynamically create associated objects and any other initialization tasks needed when introducing an object. The special destructor method is used to take care of any internal and program specific housekeeping when an object is no longer needed. The initialization and cleanup tasks are more useful when using dynamically allocated objects which will be covered in this section also. For simple programs with few objects (like the one in this tutorial), calling not using destructors won't cause any problems. However, in large programs and those that use large class libraries which routinely allocate and deallocate objects dynamically, the implementation of constructors and destructors is very useful.Here are are the Shape declarations again, this time using virtual methods and including constructors and destructors. Constructor TShape.Init(xx, yy, h, w: single);beginwriteln('TShape.Init');x:= xx;y:= yy;height:= h;width:= w;end;Destructor TShape.CleanUp;beginwriteln('TShape.CleanUp')end;Constructor TSquare.Init(xx, yy, h, w: single);beginwriteln('TSquare.Init');x:= xx;y:= yy;height:= h;width:= w;if height width thenheight:= width;end;Again, the implentation of constructors look like regular methods except the keywords constructor and destructor are used instead of the keywords procedure and function.
How To Use Focusrite Scarlett 2i2
Consider the following main program.