Posts

Showing posts from 2015

Abstract Classes and Final Classes in Delphi

Abstract Classes in Delphi If a Class have at least one Abstract member then we call it Abstract Class. An Abstract member is a Class member that have only declaration on that class and the implementation of that member is expected to be done in its descendant classes. An Abstract Class can have normal methods also. In Delphi it allows to create Object of an Abstract Class but we should not create because when we try to access any Abstract member then we will get run time  exceptions. And if a class is having only Abstract members then it is called as pure Abstract class. Why we use Abstract Class? An Abstract Class is written when there are some common features are shared by all the objects. Suppose in your project if you have some common features then declare that type of properties and methods as Abstract and you can extend wherever you want in your Module For example... If you want to make a new car(WagonX) in which all the another car's properties are included li

Delphi Classes and Objects

Classes in Delphi A Class consists of fields, methods and properties which defines character and behavior of an object. Instances of a Class are called as Objects and fields, methods are called as class members. -> A Field is essentially a variable that  is part of an object. -> Methods are procedures or functions that associated with a class and which operates on Class Objects. -> Property is an interface to data associated with an Object. A property have access specifiers which defines how the data will be read and modified. Objects are dynamically allocated blocks of memory whose structure is determined by their Class type. Each object has a unique copy of every field defined in the class, but all instances of a class share the same methods. Objects are created and destroyed by special methods called Constructor and Destructor . A variable of a Class is actually a pointer that references an object. Hence more than one variable can refer to the same obj

Generic Types and Classes in Delphi

Generic Classes in Delphi Generics are powerful language features that allows to write type-safe classes, methods that act upon a type to be provided later. Generic classes makes it possible to bind a specific type with a class that means we can instantiate a class tied to a given data type. This makes code type safer. We can declare  generic type to accept any type, or we can use constraints, which will limit the types that can be passed to ones with parameterless constructors, or types of a specific class or those that implement specific interfaces. Once we define a specific type on generic declaration, this is enforced by the compiler that we cannot assign a different type value to the class member. Generic classes are as efficient as normal classes but in some case it is more efficient than other classes as the need for runtime type cast is reduced. Generally we use Generics  on cases when we need lots of type casting with a specific type or we are writing a lots of sub classes

E2003 Undeclared identifier 'ShortDateFormat' error in Delphi XE3 or later versions

E2003 Undeclared identifier 'ShortDateFormat' error in Delphi XE3  or later versions When we upgrade a Delphi old version application to Delphi XE3 or latest one then if we have used ' ShortDateFormat ' global variable in our project then we will get 'E2003 Undeclared identifier 'ShortDateFormat' compiler error. Why we get this error? As some global variables typically pertain to Date, Time and Currency format ( CurrencyString , ShorDateFormat, LongTimeFormat, ShortMonthNames, and so on) have been deprecated and removed declaration from Delphi XE3 or later versions. In old Delphi versions we can find this variables declaration in 'System.SysUtils' unit but from Delphi XE3 those are moved with TFormatSettings Record. Workarounds to solve this error. We can replace ' ShortDateFormat ' with 'Formatsettings.ShortDateFormat'. And ' FormatSettings ' is a global variable of 'TFormatSettings' type declared in