Quantcast
Viewing all articles
Browse latest Browse all 10

Use Dephi 5 – part IV-

Programming in Delphi:
Lesson 1 – Object Oriented Programming (OOP)
The notion of object. Features:
OOP idea is to put together in one container, both the data and code (procedures and functions, which are called methods). Container is called object.
Objects relevant to the user (programmer using the object) only what
necessary, so use the object to be as smooth. All internal mechanisms that the user does not need to know are hidden. OOP enables a modular approach to programming, what windows we need to rewrite parts of the code.
Another important feature is object inheritance. The inheritance property of objects that are understood by a newly constructed object takes the data and methods of another object, parent. This feature allows us to quickly and easily write similar objects that have some common data and methods.
It may be that some methods of a class to be rewritten so that, even
Where a class is descending method with the same name, to do something else. This feature is called polymorphism.
The notion of class. Characteristics.
A class or a class type defines a structure that contains fields, methods and
properties. Court a type of class is called obiect1.
A field is actually a variable that is part of an object. Like the fields of a record field of a class represents a date that exists in each instance of a class.
A method is a procedure or function associated with a class. Most methods operate on objects that are instances of classes.
A property is an interface for an object associated date (date which is usually stored in a field). The properties have access specifies that determine how data can be read or modified. The program, outside the object, a property often appears as a field.
For dynamic objects are allocated memory blocks whose structure is determined by the type of class. Each object has a single copy of each field defined in class, but all instances of a class share the same methods. Objects are created and destroyed using special methods called constructors and destructor.
Constructor is a method used to create an instance of a class. Has
initializing role of some fields to allocate memory, or do whatever is necessary to boot object. It is not mandatory to define a constructor, if it is not defined using default constructor Create.
Destructor is a special method is automatically called to destroy the object.
Destructor is usually seen as the inverse of the manufacturer, taking care of his memory allocated to the class. Each class is not required to have a destructor.
Visibility of class members.Image may be NSFW.
Clik here to view.

Each member of a class has an attribute called visibility, which is indicated by one of the reserved words: private, protected, public, published.
Visibility determines how members can access:
In standard Pascal notion of class does not exist, being replaced by the object, there may occur some confusion. The definition above is valid for Delphi and Pascal do not.

• Private – private member is invisible outside the class is declared, otherwise
said a method declared as private can not be called from another module, a field or property can not be read or written in another way
• Protected – protected member is visible only in the class was declared and all classes downward.
• Public – a public member is visible outside the class.
• Published – this mode of access used when writing components. All members’ statement in this area will be visible in Object Inspector.
Delphi is used in writing programs as much OOP components are used in particular. These components are objects (but not all objects are components!) That is either user created or are coming together with Delphi’s, and can be reused in any other program.
Present below a component of derivative TAnimate2 Tanimate:
type
TAnimate2 = class (TAnimate)
Private
(Private declarations, all that is said below is not visible outside the class)
fhintimage: Tbitmap;
fhintcolor: Tcolor;
fshowimage: boolean;
Procedures and functions ()
SetHintImage procedure (v: Tbitmap)
SetHintColor procedure (v: Tcolor)
setshowimage procedure (v: boolean);
afisimg procedure (Sender: TObject);Image may be NSFW.
Clik here to view.

CMHintShow procedure (var Message: TMessage) CM_HINTSHOW message;
protected
(Protected declarations)
public
(Public declarations)
constructor Create (AOwner: TComponent) override;
destructor Destroy; override;
published
(Published declarations)
(To read the variable property is read HintImage fhintimage and procedure is used to write it SetHintImage)
Property HintImage: Tbitmap read fhintimage SetHintImage written;
(Property below is defined and a default value (clwhite – white))
Property HintTransparentColor: Tcolor read fhintcolor clwhite wrote SetHintColor default;
Property ShowHintImage: boolean read write fshowimage SetShowImage default false;
property assets;
align property;
property Anchors;
Autosize property;
property BorderWidth;
Center property;
property Color;
CommonAVI property;
property constraints;
property Cursor;
FileName property;
property Height;
HelpContext property;
Property Hint;
property Left;

Property Name;
ParentColor property; ParentShowHint property; Repetitions property; ShowHint property;
StartFrame property; StopFrame property; property Tag; Timers property; property Top;
property Transparent; property Visible; Width property; {******** Events) OnClose property;
OnOpen property; property OnStart; OnStop property; onclick property; OnMouseMove property;
end;
In the example above you have noticed that appeared override, which tells us that that method can be rewritten so that a derived class that method can perform a completely different code. If the user wants to have  rewrite he can add a virtual method in the right method.11


Viewing all articles
Browse latest Browse all 10

Trending Articles